|
I have failed in my attempts to get the text "product foo provides a low cost solution for a broad range of applications." from the following XML snippet:
<app.descriptions readable.name="Application descriptions"> <description arg1="val1" arg2="val2" arg3="val3" field="Application Description">product foo provides a low cost solution for a broad range of applications. </description> </app.descriptions> any help would be greatly appreciated! |
|
This worked for me in 2.0.0.0-beta-2 GroovyConsole:
--- def xml = """ <app.descriptions readable.name="Application descriptions"> <description arg1="val1" arg2="val2" arg3="val3" field="Application Description">product foo provides a low cost solution for a broad range of applications. </description> </app.descriptions> """ def appDescriptions = new XmlSlurper().parseText(xml) println appDescriptions.description println appDescriptions.description.@field println appDescriptions.@'readable.name' --- Gives: --- product foo provides a low cost solution for a broad range of applications. Application Description Application descriptions --- It should work in earlier versions as well... HTH BOB > -----Original Message----- > From: CosmicRider [mailto:[hidden email]] > Sent: Wednesday, 25 April 2012 10:46 AM > To: [hidden email] > Subject: [groovy-user] Another XMLSlurper question > > I have failed in my attempts to get the text "product foo provides a low cost > solution for a broad range of applications." from the following XML > snippet: > > > <app.descriptions readable.name="Application descriptions"> > <description arg1="val1" arg2="val2" arg3="val3" field="Application > Description">product foo provides a low cost solution for a broad range of > applications. </description> </app.descriptions> > > any help would be greatly appreciated! > > > -- > View this message in context: > http://groovy.329449.n5.nabble.com/Another-XMLSlurper-question- > tp5663611p5663611.html > Sent from the groovy - user mailing list archive at Nabble.com. > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
In reply to this post by CosmicRider
new XmlSlurper().parseText(xmlString).description.text()
The example from XmlSlurper documentation covers your use case: http://groovy.codehaus.org/api/groovy/util/XmlSlurper.html Cheers, Dinko On 25 April 2012 02:45, CosmicRider <[hidden email]> wrote: > I have failed in my attempts to get the text "product foo provides a low cost > solution for a broad range of applications." from the following XML > snippet: > > > <app.descriptions readable.name="Application descriptions"> > <description arg1="val1" arg2="val2" arg3="val3" field="Application > Description">product foo provides a low cost solution for a broad range of > applications. </description> > </app.descriptions> > > any help would be greatly appreciated! > > > -- > View this message in context: http://groovy.329449.n5.nabble.com/Another-XMLSlurper-question-tp5663611p5663611.html > Sent from the groovy - user mailing list archive at Nabble.com. > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
In reply to this post by Bob Brown
Bob, thanks for the quick reply. I am surprised by the actual solution, which means there is a gap in my understanding. Could you please explain why appDescriptions.description generates the correct result? My initial thought was that "product foo provides..." was a value off of the field attribute
|
|
Not really, "product foo provides..." is the CONTENT of the <description>
Element. The value of the field attribute is " Application Description" (no quotes). And, as Dinko pointed out, I probably SHOULD have use .text(): println appDescriptions.description.text() println [hidden email]() println appDescriptions.@'readable.name'.text() BOB > -----Original Message----- > From: CosmicRider [mailto:[hidden email]] > Sent: Wednesday, 25 April 2012 2:00 PM > To: [hidden email] > Subject: [groovy-user] RE: Another XMLSlurper question > > Bob, thanks for the quick reply. I am surprised by the actual solution, which > means there is a gap in my understanding. Could you please explain why > appDescriptions.description generates the correct result? My initial thought > was that "product foo provides..." was a value off of the field attribute > > -- > View this message in context: > http://groovy.329449.n5.nabble.com/Another-XMLSlurper-question- > tp5663611p5663831.html > Sent from the groovy - user mailing list archive at Nabble.com. > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
| Powered by Nabble | Edit this page |
