tags:

views:

1236

answers:

1

I have a DataRow with columns col1 and col2. Each column has a value: val1 and val2 respectively. How can I turn this into an xml string using C#?

For the DataRow mentioned above I'd like the following string:

<col1>val1</col1><col2>val2</col2>
+3  A: 

Put the DataRow into a new DataTable. Then call writeXml on the dataTable.

Technically correct, but I would council against this, largely as you have no control over the XML outputted.

I would loop through the rows of the table and use the System.Linq.XML classes to properly format your XML (or if you're feeling more perverse, try XMLDocument and related classes)

johnc