Author Login
Post Reply
What about this approach (not sure it is the best one):
def text = """
<data>
<common-tables>
<table name="address"/>
<table name="phone"/>
</common-tables>
<special-tables>
<table name="person"/>
</special-tables>
<other-tables>
<table name="business"/>
</other-tables>
</data>
"""
def xml = new XmlParser().parse(new ByteArrayInputStream(text.getBytes()))
def tables = xml.'**'.table.findAll{ it.parent().name() ==
"special-tables" || it.parent().name() == "common-tables"}
tables.each {println it}
Regards,
Sergey Bondarenko.
2008/8/21 grkuntzmd <grk@(protected)>:
> I played with this yesterday for about 1/2 hour, but could not come up with
> the right GPATH code
>
> I have an XML document with the following structure:
>
> <data>
> <common-tables>
> <table name="address"/>
> <table name="phone"/>
> </common-tables>
>
> <special-tables>
> <table name="person"/>
> </special-tables>
>
> <other-tables>
> <table name="business"/>
> </other-tables>
> </data>
>
> I was trying to come up with GPath code that lets me get the name attributes
> from the table elements, but only if they are under the "common-tables" or
> "special-tables", excluding those under the "other-tables".
>
> I tried both XmlParser and XmlSlurper, and all combinations of findAll that
> I could think of.
>
> I am a Groovy-Newbie (I should trademark that :-)) and searched the Groovy
> home, as well as all of my Groovy books.
>
> Any ideas?
>
> G. Ralph Kuntz, MD
> Chief Software Architect
> meridianEMR, Inc.
> ________________________________
> View this message in context: Q: Avoiding XPath - using GPath
> Sent from the groovy - user mailing list archive at Nabble.com.
>
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email