I have a Xml file, ( actually HTML tags ) , I want to use the SelectNodes method to get ANY node/tag containing a keyword. The node name can be anything <td> , <div> <p>
. What is the XPath to get any node which contains a keyword?
views:
25answers:
1
+3
A:
This XPath expression:
/html/body//*[text()[contains(.,'keyword')]]
This means: any element descendant of body
having a text node child with the string 'keyword' contained in its string value.
Edit: Better predicate 'cause probably there is more than one text node child...
Alejandro
2010-09-15 23:11:26
+1 for a precise answer.
Dimitre Novatchev
2010-09-16 01:23:34
Thanks for your reply. This works for some pages and some other pages throw exception. Of course all of them contain Body and HTML Tags. Do you have any idea what can cause to through exception?? ( Object reference not set to an instance of an object )
2010-09-16 04:31:41
If you have code that throws an exception then post the minimal code and a minimal input that allows us to reproduce and understand the exception. I don't see why `For Each el As XmlElement In someXmlDocument.SelectNodes("/html/body//*[contains(text(), 'keyword')]` would throw an exception.
Martin Honnen
2010-09-16 11:48:08
@user445891: Maybe you are trying to do something with an empty node set?
Alejandro
2010-09-16 12:41:54