Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the non-empty element using XPATH

Tags:

xpath

I have the following XML

<?xml version = "1.0" encoding = "UTF-8"?>
<root>
  <group>
    <p1></p1>
  </group>
  <group>
    <p1>value1</p1>
  </group>
  <group>
    <p1></p1>
  </group>
</root>

is it possible to get the last the node with value? in this case get the value of the second group/p1.

like image 425
Rowel Avatar asked Sep 01 '25 22:09

Rowel


1 Answers

This xpath should work as well:

//group/p1[string-length(text()) > 0] 
like image 196
Nora Avatar answered Sep 05 '25 13:09

Nora