Is there a way to check if the node I'm looking for using XPATHcontains trays or not?
I have an xml file in which a certain node sometimes has children, but for some time it hasn’t! How to check this, so I do not get too many NullReferenceExceptions !?
See an example below:
var text = xml.SelectSingleNode("/Document/Tests/Test").InnerText;
If the current xml file I'm working with has a Testnode inside it Tests, it works fine, but the Testsnode doesn’t contain anything in another XML file , and it’s just there for no apparent reason !?
Is there a command in XPATH for this? sort of!!
"/Document/Tests[NodeExist(Test)]
source
share