• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 444
  • Last Modified:

Custom XML Writer


I need to generate an XML file based on data in an ADO.NET DataSet.  I realise the DataSet object has a simple WriteXml() method but I need the XML in a very specific structure.

My question is this:  Is it completely wrong or out of the ordinary to write a custom XML Writing method..?  I mean, for example, a method that iterates through all the data in a DataSet, one row at a time, and writes it to a TextStream with the tags and elements exactly as they are required..?

Is there another way..?

1 Solution
i think the easiest way serizlize DataSet using WriteXml() and then apply XSLT transformation to create the structure you want.

Certanly you can write your custom method to serialize DataSet in yours format, if you have really problems with XSLT.

But i think XSLT will be easier to develop
it depends, if the data is large then you are better off using the XmlTextWriter and write the data thru this object. It is lighter and performs faster than getting the Xml through the WriteXml() method  and then performing element transformations through Xslt.

If you do not wish to recompile your application every time there is a structural change in your Xml Requirements, then you should go ahead with Xslt on the proviso that the data is not large (say not more than 500 rows of say 5 columns: it is admittedly a subjective field. But with MSXML.NET, anything about 200KB can be dreadfully slow in transforming as contrasted to using the XmlTextWriter.

If you want it to be performant-oriented due to the largeness or potential largeness of the data, then the only way to go is the use of the XmlTextWriter.

I'd say in most cases where the data is not large, XSLT is the way to go because it affords flexibility in making changes. However, if performance is dreadful or unacceptable then, you must use the XmlTextWriter.
XSL is easier but way too slow.  Just overload the WriteXML and make your own.  Use XMLTextWriter for fastest access or XMLDocument if you want to save some coding and sacrifice some speed.

You may end up writing a serializer and a deserializer if you need to bring your data back in.  This is not uncommon at all, I usually end up writing several custom serializers in an application.
TDSnetAuthor Commented:
Okay thanks guys, I'm going with the XmlTextWriter.

b1xml2 gets the poinx.

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now