-1

Can anyone help me to get the Z NAMES data with only one xpath syntax?

<fields>
 <field name="Z01NAME">Romulo</field>
 <field name="Z02NAME">Marco</field>
 <field name="Z03NAME">Tan</field>
 <field name="X01NAME">Joseph</field>
 <field name="X02NAME">EXB</field>
</fields>

I tried /fields/field[@name="Z*NAME"] but it doesn't work. Appreciate the help!

Ishara Madhawa
  • 3,549
  • 5
  • 24
  • 42
Romz Marco
  • 13
  • 1

1 Answers1

0

The XPath 1.0 does not support wilcards or regular expressions. You could solve the question using starts-with(), function. To implement ends-with() function use @IanRoberts' answer. So, the final expression is

/fields/field[starts-with(@name,'Z') and substring(@name, string-length(@name) - string-length('NAME') +1) = 'NAME']
Alexander
  • 4,420
  • 7
  • 27
  • 42
  • the 'ends-with' function is not working, but starts-with partially answers my question and is a big help already. Thank you!. – Romz Marco Apr 26 '18 at 05:10
  • @RomzMarco, you are right! The `ends-with()` implementation is proposed in the [Xpath “ends-with” does not work](https://stackoverflow.com/q/22436789/7914637) topic. – Alexander Apr 26 '18 at 05:37