473,399 Members | 4,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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

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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #1
2 5197
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
"Kathy Burke" <ka**********@attbi.com> wrote in message
news:eY**************@TK2MSFTNGP11.phx.gbl...
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

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

Nov 17 '05 #2
Thanks, Justin. That did the trick of course. I wasn't using the
"nothing"...

thanks.

Kathy

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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: moxm | last post by:
I have a statement declares a globle variable like this : char *pname = NULL; Then I used splint to check the code, I got errors: err.c:8:15: Global pname initialized to null value: pname =...
7
by: Dan | last post by:
I'm fairly new to C# and I am having some problems understanding int variables and null values. I have created a class that populates the values of it's fields from a DataReader in it's...
1
by: Vern | last post by:
I'm using the Microsoft Enterprise Data Access block to call the stored procedure. One of the values the stored procedure returns is the stop date. When the stop date is null, the program crashes....
0
by: linear | last post by:
just a test
3
by: Giorgio Parmeggiani | last post by:
HI I have a method that receive a generic parameter and also return a generic: public T GetById(ID id) I've want to return null if the received parameter is null, so i have write this code:...
17
by: Mark A | last post by:
DB2 8.2 for Linux, FP 10 (also performs the same on DB2 8.2 for Windoes, FP 11). Using the SAMPLE database, tables EMP and EMLOYEE. In the followng stored procedure, 2 NULL columns (COMM) are...
15
by: Tarun Mistry | last post by:
Hi guys, what is the best/correct way to check for a NULL object? I.e. myClass test; if(test == null) {}
12
by: sprightee | last post by:
Hi, I've a simple object class as testObj.java with getter and setter methods. In my code i need to check if the testObj object is null. My code is : testObj test = new testObj(); //invoke a...
3
by: Akhenaten | last post by:
I have the following function which works great except when I encounter a NULL value in my array ($aidlook) and then I get "wrong data type" errors. I thought about doing a NULL check and creating...
1
by: sreemati | last post by:
ssue: ------ I am working on a health care system and currently facing problem with NULL values being introduced as part of my SQL query. What is the query trying to do? The query is trying to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.