No Nodes Selected from Atom XML document using XPath?

这一生的挚爱 提交于 2019-11-28 12:19:08

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);
Mathulan

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!