XML解析在XML中具有嵌套循环

时间:2017-05-07 11:28:06

标签: xml-parsing

Please help me in this code 
I am suing a nested XML like 

    <agn:TXLife xmlns:agn="http://ACORD.org/Standards/Life/2/Sales/v1" xmlns:ext="http://allstate.com/dmea/Sales/v1">
    <agn:OLifEExtension>
                <agn:OLifEExtension>
                  <ext:NetworkID>JBROWN</ext:NetworkID>
                </agn:OLifEExtension>
              </agn:OLifEExtension>
    </agn:TXLife>

我无法获取networdID“JBROWN”。请建议我。

1 个答案:

答案 0 :(得分:0)

如果您使用c#,则可以使用XmlDocument类 这是一个可以帮助您的代码:

 XmlDocument doc = new XmlDocument();
 doc.Load(path);

 XmlNode root = doc.FirstChild;//Take the root node

 for (int i = 0; i < root.ChildNodes.Count; i++)
 {
  var OLifEExtension = root.ChildNodes[i];
  var innerOLifEExtension = OLifEExtension.FirstChild;
  var NetworkID = innerOLifEExtension.FirstChild;
  Console.WriteLine("NetworkID: " + NetworkID.InnerText);
 }