I'm tring to get a string from a DataSet without using GetXml. I'm using WriteXml, instead. How to use it to get a string? Thanks
The WriteXml method provides a way to write either data only, or both data and schema from a DataSet into an XML document, whereas the WriteXmlSchema method writes only the schema. To write both data and schema, use one of the overloads that includes the mode parameter, and set its value to WriteSchema .
In an XML representation of a DataSet, the data is written in XML and the schema, if it is included inline in the representation, is written using the XML Schema definition language (XSD). XML and XML Schema provide a convenient format for transferring the contents of a DataSet to and from remote clients.
The XmlTextReader, XmlNodeReader and XmlValidatingReader classes are derived from XmlReader class. As their name explains, they are used to read text, node, and schemas. The XmlWrite class contains functionality to write data to XML documents. This class provides many write method to write XML document items.
All you need to do is call the WriteXml method of your DataSet and pass the full path of the XML file. This example creates a DataSet, fills the data for the DataSet, and writes the data to an XML file.
StringWriter sw = new StringWriter(); dataSet.WriteXml(sw); string result = sw.ToString();
Write to a StringWriter
, and then call ToString
on that.
Note that if you want the generated XML declaration to specify UTF-8 instead of UTF-16, you'll need something like my Utf8StringWriter
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With