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

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
 
S

S. Justin Gengo

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
 
K

Kathy Burke

Thanks, Justin. That did the trick of course. I wasn't using the
"nothing"...

thanks.

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,773
Messages
2,569,594
Members
45,120
Latest member
ShelaWalli
Top