No Nodes Selected from Atom XML document using XPath?

前端 未结 2 1495
名媛妹妹
名媛妹妹 2020-12-11 04:33

I\'m trying to parse an Atom feed programmatically. I have the atom XML downloaded as a string. I can load the XML into an XmlDocument. However, I can\'t traver

2条回答
  •  温柔的废话
    2020-12-11 05:12

    Load XML from a string and lookup for any 'Errors/Error' nodes.

    XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.LoadXml(xmlResult);            
    XmlNamespaceManager nm = new XmlNamespaceManager(xmlDoc.NameTable);
    nm.AddNamespace("ns", "http://somedomain.com/namespace1/2"); //ns - any name, make sure it is same in the below line
    
    XmlNodeList errors = xmlDoc.SelectNodes("/ns:*//ns:Errors/ns:Error", nm);       
    

    -Mathulan

提交回复
热议问题