groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Carl Marcum <cmar...@apache.org>
Subject Re: XML node access by variable
Date Fri, 11 Mar 2016 11:31:20 GMT
On 03/11/2016 03:08 AM, bartoleo wrote:
> One way is using 'index notation':
>
> report.R.each {item ->
>   println item[myTag]
> }
>
> or GString
> report.R.each {item ->
>   println item."$myTag"
> }
>
> report.R."$myTag".each {item ->
>   println item
> }
>
> Leo
>
> 2016-03-11 5:46 GMT+01:00 Carl Marcum [via Groovy] <[hidden email] 
> </user/SendEmail.jtp?type=node&node=5731833&i=0>>:
>
>     I'm using XML Slurper to parse an XML file with this type of format:
>
>     <R>
>        <C0>...</C0>
>        <C1>...</C1>
>        <C2>...</C2>
>     </R>
>       <R>
>        <C0>...</C0>
>        <C1>...</C1>
>        <C2>...</C2>
>     </R>
>     ...
>
>     The XML file node names are constantly changing so I would like to
>     use a
>     variable for the node designations.
>
>     defreport =newXmlSlurper().parse(myXmlFile)
>
>     instead of access the C1 node like:
>     report.R.each() {item ->
>     item.C1
>     }
>
>     I'm using:
>     def myTag = "C1"
>     report.R.each {item ->
>     item.getProperty(myTag)
>     }
>
>     Is there a shorter way to access the node by variable without
>     getProperty(tagVar)?
>
>     Thanks,
>     Carl Marcum
>     Apache OpenOffice committer and PMC
>
>
>
>     ------------------------------------------------------------------------
>     If you reply to this email, your message will be added to the
>     discussion below:
>     http://groovy.329449.n5.nabble.com/XML-node-access-by-variable-tp5731831.html
>
>     To start a new topic under Groovy Users, email [hidden email]
>     </user/SendEmail.jtp?type=node&node=5731833&i=1>
>     To unsubscribe from Groovy, click here.
>     NAML
>     <http://groovy.329449.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>
>
>
>
>
> -- 
> Leo Bartoloni
>
> -----------------------------------------------------------------------------------------------------------------------------------------------------------
> Qualsiasi utilizzo non autorizzato del presente messaggio e dei suoi 
> allegati è vietato e potrebbe costituire reato.
> Se lei avesse ricevuto erroneamente questo messaggio, Le saremmo grati 
> se provvedesse alla distruzione dello stesso
> e degli eventuali allegati.
> Opinioni, conclusioni o altre informazioni riportate nella e-mail, che 
> non siano relative alle attività e/o
> alla missione aziendale. si intendono non attribuibili alla società 
> stessa, né la impegnano in alcun modo.
>
> ------------------------------------------------------------------------
> View this message in context: Re: XML node access by variable 
> <http://groovy.329449.n5.nabble.com/XML-node-access-by-variable-tp5731831p5731833.html>
> Sent from the Groovy Users mailing list archive 
> <http://groovy.329449.n5.nabble.com/Groovy-Users-f329450.html> at 
> Nabble.com.

That's great!

Thanks Leo !!

Carl

Mime
View raw message