tags:

views:

76

answers:

1

Hi There,

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 parent.SelectChildNode() to access the value of that node?

Many thanks

b

A: 

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;
  // ...
}
Tomalak
Fantastic, thank you Tomalak, i will give that try!
Just to follow up, thanks again Tomalak this worked perfectly. Much appreciated.
@user: Thanks for the follow-up, glad that it worked. P.S.: An up-vote and an accept for this answer would be very much appreciated on my end. ;-)
Tomalak