2017-05-07 37 views
1
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”。请在此建议我。在XML中具有嵌套循环的XML解析

+0

在哪种语言,你要分析此XML? –

+0

欢迎来到计算器。请,你能提供一些你的具体问题的代码吗?这可以证明你尝试了多远,它会帮助其他成员更好地理解你的问题,当时,你会给他们一个你的问题的背景。请检查这些链接:https://stackoverflow.com/help/mcve和https://stackoverflow.com/help/how-to-ask –

+0

XDOC的XDocument = XDocument.Load(路径); xDoc.Descendants(AGN + “OLifEExtension”)。后代(),选择(p值=>新 { NETWORKID = p.Element(EXT + “NETWORKID”)。值 })ToList。()。 ForEach(p => {String} Result_OLIFEExtension = p.NetworkID; Logwrite(Result_OLIFEExtension.ToString(),Dtime); }); } –

回答

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); 
} 
+0

感谢您的快速解决方案: 但是我们无法进入for循环,因为它显示的是root.ChildNodes.Count = 0; –

+0

是xml文件,看起来像您发布的xml文件? – TomerMahari

+0

<?xml version =“1.0”encoding =“utf-8”standalone =“yes”?> ACORD_2.17_EPCSI_20161125 A 2016-11-25