No Nodes Selected from Atom XML document using XPath?

前端 未结 2 1510
名媛妹妹
名媛妹妹 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:04

    While the C# implementation may allow default namespaces (I don't know), the XPath 1.0 spec doesn't. So, give "Atom" its own prefix:

    nsMngr.AddNamespace("atom", "http://www.w3.org/2005/Atom");
    

    And change your XPath appropriately:

    XmlNode node = atom.SelectSingleNode("//atom:entry/atom:link/app:edited", nsMngr);
    

提交回复
热议问题