How to use XML and XML Schemas with C# - c#

HI,
I want to keep the Outlook contacts in an XML file. And I want to compare, merge and resolve conflicts of this XML file with another XML file which may have same attributes ?
Also I want to know when a particular node is editied/newly added ? How we can achieve this in XML using C# 3.5 ? Should I use any XML Schemas ? How this is possible ?
Also please let me know using which one is faster - a XML file or a SQLite ?

You can use LINQ to XML, there are various books on LINQ to XML, please refer them.
for small data XML should be fast and effective way to go like configuration data, etc.
for large data SQLite is the way to go.

Related

Generate XML file from CSV using XSD

I am trying to implement a C# Windows Forms application to generate XML file from a CSV based on XML's schema. I want to do this as much generic as possible since I am going to transform more than 1000 csv/schemas. Any ideas would be appreciated.
There is a pretty good article exposing appropriate approach for this case
converting csv to xml with an xsd

import - xpath or convert to .csv?

Im looking for some advice on how I should go about a solution. I have an import to write using c#. The data comes from an xml file containing ~30000 records each with ~10 nodes for differnet data. My initial thought would be to create a node list of records ids(one of the nodes is a unique id). Then loop through the node list and use xpath to get the rest of the data for the record. My other thought was to convert the xml file into .cvs format and read it that way. Before i dive head first into one or the other any advice, pros/cons or suggestions? Thanks in advance
Go with whichever you feel more comfortable with.
Personally, I would use XDocument and LINQ to XML to query the XML directly.
Transforming to CSV has its own pitfalls, if you don't adhere to the rules (quoting fields, line breaks within fields etc...).
I agree with the above poster that you want to use LINQ to XML if possible, however if you are on an older version of the framework you could use an XMLDocument and the SelectNodes/SelectSingleNode methods. If you do that however make sure you use a NamespaceManager or you won't return anything from your methods unless your XML has no namespaces etc.
That got me a bunch of times.

Approach to process huge xml files in C#

Can someone please guide me with this problem?
In my institution, we process xml files of huge size(max 1 GB) and insert the details into a database table. Per current design, we are parsing xml file with XmlReader and form a xml string with required data, which will then be passed into a stored procedure (xml data type) to insert the details into db.
Now the problem is we are not sure if there would be a better approach other than this ? so please suggest if are any new features available with .Net 3.5 and/or sql server 2005 to handle this in a way better than our approach.
Any help in this reagrd would be highly appreciated.
Thanks.
Do you care at all what is in the XML-file? If not, you can just use a StreamReader and get the text from the XML and just pass it along to the database.
If you need to validate that the XML is correct, it is a good idea to use XmlReader.
However, just dumping 1GB of XML into your database seems a bit weird, what is the purpose of this XML data? Is it a lot of nested elements? Maybe you could de-serialize it and store each object in the appropriet table instead, which would imo lead to a easier understandable design.
There are a couple of things you can think of to make the design of your software easier/better:
Does more than one XML file occure in the database at once?
How is the data shared between applications?
Have you considered using MemoryMappedFile?
Is it possible to de-serialize the XML into entities instead and store them approprietly?
I suspect that if there are any performance issues it will be with the stored procedure and the database side of things rather that reading the file.
Why are you storing the XML file in a database table? I would suggest using a different solution would be appropriate, but without knowing more details about exactly what it is you are trying to do it is hard to advise.
If each first-level element in the xml is a record, i.e.
<rootNode>
<row>...</row>
<row>...</row>
<row>...</row>
</rootNode>
Then you could create an IDataReader implemention that reads the xml (via XmlReader) and presents each as a record, to be imported using SqlBulkCopy. Pretty much like my old answer here.
Advantages:
SqlBulkCopy is the fastest way to get data into a database
stripping it into records makes appropriate use of a database, allowing indexing and proper typing
it doesn't rely on a huge BLOB going over the wire in an atomic way (necessary for the xml data type)

XML data in binary files or straight XML file for asp.net application?

We have a need to save some of our configuration items into files. I have been told this is for some localization features we are going to use. From what I have been told, it is much faster to read from a binary file than a straight XML file. Is this true, and is it ideal to save xml data in binary format or is there another way I should save the data to pull it into my web application?
I would like to be able to read the data using LINQ or casting it as an object. Also, what is the best way to parse the file for sepecific data? Any suggestions would be greatly appreciated?
I would recommend using XML over binary simply because it's easier to work with. Binary is faster but I doubt you would notice that speed gain in your application, especially if you cache the values you read from the file.
The easiest way to parse the XML file would be to deserialize it to an object using the XmlSerializer class. This is absolutely the most painless way to parse XML in my opinion.

Import 60mb XML file to SQL

I have a 60mb XML file that has a list of products, approx 8k of them. I need to get all the products from this xml file to a SQL table. The xml file has a static name so i know what to look for. I guess i want to know about the process, what makes the most sense and least overhead.
How?What? is the best way to do this?
When do i parse the xml, so i have SQL handle it, or some other method. in the past i have used a parser in a stored proc, but the old xml files where smaller, like 1-5mb, im not sure if a 60mb xml file will work.
Thoughts, Ideas?
Create a SSIS package so that you can rerun it. Have SQL handle the parsing by including the schema within the xml file.
It would probably be best to write a short program in a language that has both an XML parser and a DB interface. C#, Perl, Python, Java, whatever you know best.

Categories

Resources