日期:2014-05-18  浏览次数:20680 次

请教Xml文件to DataSet
以下XML文件如何读入DataSet,请教一下:

<?xml version="1.0" encoding="gb2312"?>
<doc>
  <table name="User_info" pk="ID">>
  <Main>
  <record>
  <ID>&lt;![CDATA[001]]&gt;</ID>
  <name>&lt;![CDATA[张三]]&gt;</name>
  <sex>&lt;![CDATA[男]]&gt;</sex>
  </record>
  <record>
  <ID>&lt;![CDATA[002]]&gt;</ID>
  <name>&lt;![CDATA[李四]]&gt;</name>
  <sex>&lt;![CDATA[男]]&gt;</sex>
  </record>
</Main>

<table1>
  <record>
  <ID>&lt;![CDATA[001]]&gt;</ID>
  <field1>&lt;![CDATA[c1]]&gt;</field1>
  <field2>&lt;![CDATA[d2]]&gt;</field2>
  </record>
  <record>
  <ID>&lt;![CDATA[002]]&gt;</ID>
  <field1>&lt;![CDATA[c1]]&gt;</field1>
  <field2>&lt;![CDATA[d2]]&gt;</field2>
  </record>

</table1>
<table2>
  <record>
  <ID>&lt;![CDATA[001]]&gt;</ID>
  <field3>&lt;![CDATA[e1]]&gt;</field3>
  <field4>&lt;![CDATA[f2]]&gt;</field4>
  </record>
</table2>
</table>
</doc>

好象无法用dataset.readXml读入,请教一下如何能读入到DataSet?

------解决方案--------------------
遍历XML取值
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath(""));
XmlNodeList nodes = doc.GetElementsByTagName("record");
foreach (XmlNode node in nodes)
{}
------解决方案--------------------
DataSet.ReadXML("")