i am trying to select “description” from a rss feed if the title is equal to something.
in code i have this :
public static XmlDocument GetDefaultHoroscopesFeed(string StarSign){
xdoc.SelectSingleNode(string.Format("rss/channel/item/[title = '{0}']/description", StarSign));
xdoc.LoadXml(DefaultPageHoroscopeNode.InnerXml);
return xdoc;
}
but i keep getting this error : Expression must evaluate to a node-set.
Please help someone
You’re not specifying a node name inbetween
.../item/and[title = ..., therefore you won’t get back a valid node-set. Also, in RSS, the<title>node will not have a child node called<description>.You need to change your XPath
into
This will get you the
<item>node that has a<title>node with the value StarSign and then retrieve its<description>node.You could also do this using an
XDocumentand Linq to XML, like so: