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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top