Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XPATH to select all nodes which are not empty

Tags:

xml

xpath

How do I select ALL nodes which have some value and are not empty? For example, I have the following XML:

    <bbb>
        <aaa/>
        <bbb/>
        <ccc>23</ccc>
        <ddd/>
        <eee>Health</eee>
        <fff/>
    </bbb>

Here I want to select those nodes which are children of bbb and have some value i.e. the nodes ccc and eee.

like image 344
R.S.K Avatar asked Dec 10 '22 22:12

R.S.K


1 Answers

select those nodes which are children of bbb and have some value

If you want to include nodes that only contain whitespace, try:

/bbb/*[string()]

If you want to ignore nodes that only contain whitespace (<x> </x>), try:

/bbb/*[normalize-space()]
like image 188
Daniel Haley Avatar answered Dec 13 '22 12:12

Daniel Haley