logo       

GPath: descendant-or-self ?: msg#00127

lang.groovy.user

Subject: GPath: descendant-or-self ?

Hi

I like the Groovy simple syntax to query XML, but I can't find how to do the equivalent
of descendant-or-self XPath expression. For instance, how can I print the names of all
elements which tag is "X", when this tag can be used at any level of the XML
tree ?

For these two files:

1.xml:

<X name="one">
<Y>
<X name="two"/>
</Y>
</X>

2.xml:

<Y>
<Y>
<X name="one">
<X name="two"/>
</X>
</Y>
</Y>
I want to have the following output:
one
two

In XPath, I would simply do "//X/@name"

Thanks for your help




<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise