Use XPath regular expressions to search in XML data

      No Comments on Use XPath regular expressions to search in XML data

The XML ValidatorBuddy editor provides a convenient search and replace window where you can quickly find any text in your XML or JSON data. But sometimes you want to have more control on where you are actually searching for a special string. Maybe you want to search only in XML attribute values or you want to get all elements with a special name. You can use the XPath evaluator window in the editor for those tasks.

For example we could use the following regular expression to find any match of “Oak” if it appears as a separate word in any text content of an element:

XPath to find Oak as word

XPath:¬†//*[text()[matches(., ‘(^|[\t\n ])Oak($|[\t\n ])’)]]

You can also look for all elements where the tag ends with the string “name” and do the comparison case-insensitive:

xpath find name element

XPath: //*[local-name()[matches(., ‘name$’, ‘i’)]]

All details about using regular expressions in XPath statements are available on this page: String functions that use pattern matching


Leave a Reply