472,110 Members | 2,248 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Help: How to check if a node exists?

hb
Hi,

I need to check if a node exists in a XmlDocument object before to use
SelectSingleNode() to
process. I tried with
if(XmlNode.SelectSingleNode("ABC")!=null)
But this only works when the node "ABC" exists. If the node doesn't exists,
I will get an error
saying object not found. Would you please give me some help?

Thank you

hb
Nov 12 '05 #1
2 55409


hb wrote:

I need to check if a node exists in a XmlDocument object before to use
SelectSingleNode() to
process. I tried with
if(XmlNode.SelectSingleNode("ABC")!=null)
But this only works when the node "ABC" exists. If the node doesn't exists,
I will get an error
saying object not found. Would you please give me some help?


If you use
XmlNode node = xmlDocument.SelectSingleNode("ABC");
if (node != null)
I don't see a problem.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Nov 12 '05 #2
hb
It works. Thank you, Martin.
"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:OS**************@TK2MSFTNGP10.phx.gbl...


hb wrote:

I need to check if a node exists in a XmlDocument object before to use
SelectSingleNode() to
process. I tried with
if(XmlNode.SelectSingleNode("ABC")!=null)
But this only works when the node "ABC" exists. If the node doesn't exists, I will get an error
saying object not found. Would you please give me some help?


If you use
XmlNode node = xmlDocument.SelectSingleNode("ABC");
if (node != null)
I don't see a problem.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by RDRaider | last post: by
1 post views Thread by Gene Vangampelaere | last post: by
10 posts views Thread by Raymond | last post: by
9 posts views Thread by Dino Buljubasic | last post: by
1 post views Thread by shirantha | last post: by
4 posts views Thread by =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?= | last post: by

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.