Convert XML to DataSet with Strings

I have an xml file, for example:

<result> <customer> <id>1</id> <name>A</name> </customer> <customer> <id>2</id> <name>B</name> </customer> </result> 

So, I need this data populated on a DataSet, here is my code:

  var reader = new StringReader(xmldoc.InnerXml); dsDatos.ReadXml(reader); 

The problem is that it populates the dataset with two tables, each of which has one row. But I need one table with two rows.

What am I doing wrong?

PD: I use C # and I do not want to iterate through the XML file, I want to use the ReadXml method.

Thank you for your time.

+4
source share
1 answer

I assume that with .InnerXml you only read two client elements, not the root element.

Since this means that you have two root elements, it splits them into two tables.

Try using xmldoc.OuterXml .

+4
source

Source: https://habr.com/ru/post/1306824/


All Articles