By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,645 Members | 1,047 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,645 IT Pros & Developers. It's quick & easy.

Help: How to check if a node exists?

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a


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

P: n/a
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.