开发者

Convert XML to DataSet with rows

I have an xml file like this:

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

So I need that data filled on a DataSet, here is my code:

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

The problem is that it's filling the dataset with two Tables each one with a si开发者_JAVA百科ngle row. But I need a single Table with the two rows.

What am I doing wrong?

PD: I'm using C# and I don't want to iterate through the XML file, I want to use the ReadXml method.

Thanks for your time.


I'm guessing that by using .InnerXml, you're only reading the two customer elements and not the root element.

Since that means you have two root elements, it's splitting them into two tables.

Try using xmldoc.OuterXml.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜