SelectSingeNode("xpath")...how to test if null?

  • Thread starter Thread starter Kathy Burke
  • Start date Start date
K

Kathy Burke

Hi, I'm using

Dim xDoc as XmlDocument
Dim xElem As xmlElement = xDoc("xpath")

I then assign a variable to a value from the result node:
Dim r As String = xElem.Attributes.GetNamedItem("name").Value

This works fine unless there is no node returned, then I get an "object
reference not set" error.

How do you test for an empty node return?

Thanks again for all the help.

Kathy
 
Kathy,

Try:

Dim r As String
If Not xElem.Attributes.GetNamedItem("name") Is Nothing Then
Dim r As String = xElem.Attributes.GetNamedItem("name").Value
End If
--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
 
Thanks, Justin. That did the trick of course. I wasn't using the
"nothing"...

thanks.

Kathy
 
Back
Top