日期:2014-05-17  浏览次数:21050 次

XML父节点下多个同名子节点读取

<?xml version="1.0" encoding="utf-8" ?>
<list>
  <tablename id="WorkOrder" name="工单">
    <dataFiled>filed1</dataFiled>
    <dataNote>字段1</dataNote>
    <dataFiled>filed2</dataFiled>
    <dataNote>字段2</dataNote>
    <dataFiled>filed3</dataFiled>
    <dataNote>字段3</dataNote>
    <dataFiled>filed4</dataFiled>
    <dataNote>字段4</dataNote>
    <dataFiled>filed5</dataFiled>
    <dataNote>字段5</dataNote>
  </tablename>
  <tablename id="Other" name="其他">
    <dataFiled>filed1</dataFiled>
    <dataNote>字段1</dataNote>
    <dataFiled>filed2</dataFiled>
    <dataNote>字段2</dataNote>
    <dataFiled>filed3</dataFiled>
    <dataNote>字段3</dataNote>
    <dataFiled>filed4</dataFiled>
    <dataNote>字段4</dataNote>
    <dataFiled>filed5</dataFiled>
    <dataNote>字段5</dataNote>
  </tablename>
</list>


XML文件中格式是这样的 如何读取tablename下所有dataFiled和dataNote的所有信息。用逗号分隔。
谢谢

------解决方案--------------------
string result = string.Empty;

            XmlDocument xmlDocument = new XmlDocument();
            xmlDocument.Load("test.xml");

            XmlNodeList nodeList = xmlDocument.SelectNodes("list/tablename");
            foreach (XmlNode node in nodeList)