| « XML and XPath expression examples |
Convert DataTable to XML
The ADO.NET DataSet object has a method for retrieving the XML representation of the data in string format called "GetXml()".
A DataTable object however, does not. Here is a small function to quickly convert the DataTable contents to an XML string.

This function uses the DataTable's WriteXml function to write its contents into the StringWriter where the ToString() method gives us the XML string representation.
The result string will look like this.

It is relatively trivial then to load the string into and XmlDocument or XPathNavigator object.
Feedback awaiting moderation
This post has 439 feedbacks awaiting moderation...