I can do this in Xpath, but unfortunately for this particular project I am unable to use xpath.
I have the following node selected:
<client href="http://somewebsitehere.com" rel="needthisdata"></client>
clientnode.Attributes["href"].Value
correctly returns "http://somewebsitehere.com", but
clientnode.Attributes["rel"].Value
does not work?
What am I doing wrong here?
Full Usage:
foreach (XmlNode clientnode in clientnodelist)
{
Message开发者_Python百科Box.Show(clientnode.Attributes["rel"].Value);
}
The above gives a NullReferenceException, whereas replacing "rel" with "href" works fine.
I'm sure i've selected the correct node as well as innertext matches, as well as attribute.count returning 2.
Read your code. You are using clientnode
as the loop variable, but you are referencing selectednode
.
What if one particular node doesn't have a "rel" attribute? NullReferenceException
.
I would add a break at the loop and take a look at what is in my Attributes collection. Also, for kicks, try changing "rel" to something else to see if it fixes the issue.
精彩评论