I am trying to parse an Atom feed. I have XML-XML loaded as a string. I can load the XML in an XmlDocument . However, I cannot go through the document using XPath. Whenever I try, I get null .
I used this Atom feed as a test: http://steve-yegge.blogspot.com/feeds/posts/default
Calling SelectSingleNode() always returns null , unless I use " / ". Here is what I'm trying to do now:
using (WebClient wc = new WebClient()) { string xml = wc.DownloadString("http://steve-yegge.blogspot.com/feeds/posts/default"); XmlNamespaceManager nsMngr = new XmlNamespaceManager(new NameTable()); nsMngr.AddNamespace(string.Empty, "http://www.w3.org/2005/Atom"); nsMngr.AddNamespace("app", "http://purl.org/atom/app#"); XmlDocument atom = new XmlDocument(); atom.LoadXml(xml); XmlNode node = atom.SelectSingleNode("//entry/link/app:edited", nsMngr); }
I thought this was possible due to my XPath, so I also tried a simple root node query, as I knew that root should work:
// I've tried both with & without the nsMngr declared above XmlNode node = atom.SelectSingleNode("/feed");
No matter what I do, it seems like he can't choose anything. Obviously, I'm missing something; I just can't figure that out. What do I need to do to get XPath to work in this Atom feed?
EDIT
Although this question has an answer, I found out that this question has an almost exact duplicate: stack overflow
c # xml atom-feed xpath xmldocument
Dan Herbert Feb 01 '09 at 17:13 2009-02-01 17:13
source share