Last post Oct 05, 2010 12:21 PM by Martin_Honnen
Oct 05, 2010 10:59 AM|Peter Smith|LINK
Normally the code below works, EXCEPT if the xpath doesnt exist, then I get the error "Object reference not set to an instance of an object." on the 2nd line
Dim sessionXML As XmlDocument = Session("XML")
If sessionXML.SelectNodes("//root/data/compare/locations/location") IsNot Nothing Then
How can I check if the xpath exists (without a try catch preferably)?
Oct 05, 2010 11:36 AM|sansan|LINK
Check for nodes count before reading values
If sessionXML.SelectNodes("//root/data/compare/locations/location").Count > 0 Then
Try that and see if it works.
Oct 05, 2010 12:21 PM|Martin_Honnen|LINK
SelectNodes returns an XmlNodeList that can be empty if the XPath does not select any nodes but it does not give an exception. If sessioXML is Nothing then of course sessionXML.SelectNodes will give the exception you describe.