Thursday, March 29, 2012

Please clarify how null nodeset result processes?

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[@dotnet.itags.org.name='Station1'][@dotnet.itags.org.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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!Kathy, you might get better responses in the .framework group, since this
doesn't seem to be specific to ASP.NET.

--
John Saunders
Internet Engineer
john.saunders@.surfcontrol.com

"Kathy Burke" <kathyburke40@.attbi.com> wrote in message
news:%23xJL5a0aDHA.2412@.TK2MSFTNGP10.phx.gbl...
> 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
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
check if the xNode is nothing first

"Kathy Burke" <kathyburke40@.attbi.com> wrote in message
news:%23xJL5a0aDHA.2412@.TK2MSFTNGP10.phx.gbl...
> 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
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
Doesn't "If Not xNode.Value Is Nothing Then" check that xNode is
nothing?

Thanks.

Kathy

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
"Kathy Burke" <kathyburke40@.attbi.com> wrote in message
news:ei17Bx0aDHA.2024@.TK2MSFTNGP12.phx.gbl...
> 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

--
John Saunders
Internet Engineer
john.saunders@.surfcontrol.com
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

0 comments:

Post a Comment