1

For an XML document, I want to be able to find all the elements/nodes that have a certain text 'abc' in it. This text will be primarily found in the attributes (property name='abc'). The thing is the attribute name will not be known beforehand so I cannot parse the exact attribute name. Is there any way to handle this easily?

I am using XPath, but I can only solve this problem if I know what the attribute name is. I want to find elements that have the text 'abc' without knowing the attributes and such.

kt-workflow
  • 359
  • 1
  • 3
  • 14
  • Hi, please check the similar question: https://stackoverflow.com/questions/5074469/xpath-find-text-in-any-text-node – Artyom Rebrov Jul 01 '19 at 18:50
  • this is not answering my question; i basically want to find all attributes that have a certain value. not the actual text field - i tried that solution already – kt-workflow Jul 01 '19 at 18:55

2 Answers2

0

Putting my answer here:

//*[text()='some_abc_text']

will get you whole node with its text.

Artyom Rebrov
  • 651
  • 6
  • 23
0

More precise XPath expression can point to attribute values only

//*[@*='abc']
edwgiz
  • 747
  • 5
  • 15