tags:

views:

39

answers:

1

Hi, i have the following question: I have a XML file with some elements that are the response of the invocation of some webservice. The problem is that i need to load that XML file and select a specific node, but, if the websevice returns a response where the element i'm trying to extract not exist, my function SelectSingleNode will fail producing an exception. I want to control that exception but with no try catch, maybe with an if, something like:

if (xDoc.SelectSingleNode("//Node") == null) etc...

obviously it doesn't work thats easy, so thats why i'm posting this question. Hope i made myself clear. Thanks in advance.

+2  A: 

Close but I would use:-

 var node = xDoc.SelectSingleNode("//Node");
 if (node != null) // go ahead and use node.
AnthonyWJones