Please clarify how null nodeset result processes?

  • Thread starter Thread starter Kathy Burke
  • Start date Start date
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
 
Kathy, you might get better responses in the .framework group, since this
doesn't seem to be specific to ASP.NET.
 
Doesn't "If Not xNode.Value Is Nothing Then" check that xNode is
nothing?

Thanks.

Kathy
 
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
 
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
 
Back
Top