parsing XML content - C#

前端 未结 6 1601
轮回少年
轮回少年 2021-01-21 00:40

I have not used XML for very long and need to extract the useful information from an XML response. If there are 2 tags that are the same but have a different name e.g



        
6条回答
  •  情书的邮戳
    2021-01-21 01:09

    Try this to start:

    XPathDocument docNav = new XPathDocument(pathName);
    XPathNavigator nav = docNav.CreateNavigator();
    XmlNamespaceManager ns = new XmlNamespaceManager(nav.NameTable);
    
    string val =  nav.SelectSingleNode(@"/lst/lst[@name='overflow']/str")
    

    These are good resources for simple XPath navigation and .NET XML Parsing:

    http://www.w3schools.com/xpath/

    http://www.codeproject.com/Articles/52079/Using-XPathNavigator-in-C

提交回复
热议问题