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.
Close but I would use:-
var node = xDoc.SelectSingleNode("//Node");
if (node != null) // go ahead and use node.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With