Reading xml ref attribute in .NET

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)
{
    MessageBox.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.

Answers


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.


Need Your Help

Generate random sequence of integers differing by 1 bit without repeats

algorithm random

I need to generate a (pseudo) random sequence of N bit integers, where successive integers differ from the previous by only 1 bit, and the sequence never repeats. I know a Gray code will generate

How would I go about making a camera like movement in pygame

python pygame movement

My game is a platform game. I want the player to move when it is X pixels away from the center, moving left or right.