Please clarify how null nodeset result processes?

K

Kathy Burke

Hi, I continue to have trouble with this. Using the following xml
sample:

<Station name="Station1" line_stop="yes"/>

OR when NO line_stop attribute exists.

In asp.net page, I use xpath to determine IF the line_stop attribute
exists (or am TRYING to!)

Dim xDoc as XmlDocument
Dim xNode As XmlElement =
xDoc.SelectSingleNode("//Station[@name='Station1'][@line_stop='yes']")

If Not xNode.Value Is Nothing Then
If xNode.Value = "yes" Then
do this...
End If
End If

If there is no line_stop attribute, I get an error for "Object reference
not set to an instance of an object" at the If Not xNode.Value
line...obviously returning no node.

Please tell me where I'm going wrong.

Thanks,
Kathy
 
J

John Saunders

Kathy, you might get better responses in the .framework group, since this
doesn't seem to be specific to ASP.NET.
 
K

Kathy Burke

Doesn't "If Not xNode.Value Is Nothing Then" check that xNode is
nothing?

Thanks.

Kathy
 
J

John Saunders

Kathy Burke said:
Doesn't "If Not xNode.Value Is Nothing Then" check that xNode is
nothing?

No. That checks to see if xNode.Value is Nothing. If xNode is Nothing, the
above "If" statement will throw a NullReferenceException.

To see if xNode is Nothing try:

If Not xNode is Nothing Then
 
K

Kathy Burke

Hi again,

I've tried adding:

If Not n16 Is Nothing Then
If n16.Value = "yes" Then
Dim strNext As String = "yes"
End If
End If

but still get a NullReferenceException on the first line of the above
snippet. In this particular case, I SHOULD get "nothing" as a result
since the attribute 'line_stop' doesn't exist for the element
selected...but the code should then continue, yes?

Any suggestions for how I can proceed?

Kathy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,233
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top