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

OC4J 10.1.3.4 problem with deploying multiple 2.1 EJBs

java java-ee ejb oc4j ejb-jar.xml

I am having troubles migrating from OC4J 10.1.2.3 to 10.1.3.1.4. The problem is for applications that have multiple EJBs (all are 2.1, no EJB 3.0). Jdeveloper will take the default ejb-jar.xml (th...

How to prevent arrow keys from changing the UI state?

c++ winapi

I am developing a Tetris game using C++ in combination with the plain old WinAPI, GDI and GDI+. The applications window contains a few UI controls along with a static control that is used for paint...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.