|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
Q: Avoiding XPath - using GPathI 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
|
|
|
Re: Q: Avoiding XPath - using GPathWhat 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@...>: > 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 |
|
|
Re: Q: Avoiding XPath - using GPathThanks. That's exactly what I was looking for. I did not know that you could put wildcards in the GPath.
Is there any "good" documentation on GPath? Wildcards were not mentioned in any of my books. G. Ralph Kuntz, MD
|
| Free embeddable forum powered by Nabble | Forum Help |