How to parse an iCal Rss node
Can someone help me with a line of code to access an iCal node from an RSS feed?
Specifically i want to access the xCal:x-calconnect-venue-name node.
My parent node is 'item', so the path is:
item/xCal:x-calconnect-venue/xCal:adr/xCal:x-calconnect-venue-name
How can i use p开发者_如何学Carent.SelectChildNode() to access the value of that node?
Many thanks
b
If the RSS item contents is something like this (irrelevant nodes omitted)
<item>
<xCal:adr>
<xCal:x-calconnect-venue-name>venue name</xCal:x-calconnect-venue-name>
</xCal:adr>
</item>
Then you could do
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.xmlDoc);
nsmgr.AddNamespace("xCal", "urn:ietf:params:xml:ns:xcal");
// possibly add the RSS namespace as well?
XmlNodeList nodes = xmlDoc.SelectNodes("rss/channel/item");
foreach (XmlNode node in nodes) {
XmlNode venue = node.SelectSingleNode(".//xCal:x-calconnect-venue-name", nsmgr);
// watch out, there might not be a select result!
if (venue != null) {
string s = venue.InnerText;
// ...
}
}
or directly
string xpath = "rss/channel/item//xCal:x-calconnect-venue-name";
XmlNodeList nodes = xmlDoc.SelectNodes(xpath, nsmgr);
foreach (XmlNode venue in nodes) {
string s = venue.InnerText;
// ...
}
精彩评论