From users-return-1483-apmail-groovy-users-archive=groovy.apache.org@groovy.apache.org Fri Mar 11 08:08:40 2016 Return-Path: X-Original-To: apmail-groovy-users-archive@minotaur.apache.org Delivered-To: apmail-groovy-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9980518E5F for ; Fri, 11 Mar 2016 08:08:40 +0000 (UTC) Received: (qmail 81366 invoked by uid 500); 11 Mar 2016 08:08:40 -0000 Delivered-To: apmail-groovy-users-archive@groovy.apache.org Received: (qmail 81335 invoked by uid 500); 11 Mar 2016 08:08:40 -0000 Mailing-List: contact users-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@groovy.apache.org Delivered-To: mailing list users@groovy.apache.org Received: (qmail 81325 invoked by uid 99); 11 Mar 2016 08:08:40 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 11 Mar 2016 08:08:40 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id E835AC0DA2 for ; Fri, 11 Mar 2016 08:08:39 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 5.736 X-Spam-Level: ***** X-Spam-Status: No, score=5.736 tagged_above=-999 required=6.31 tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_ENVFROM_END_DIGIT=0.25, HTML_MESSAGE=2, NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_NONE=-0.0001, SPF_SOFTFAIL=0.972, URI_HEX=1.313] autolearn=disabled Received: from mx2-lw-us.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id wyn69YGseOOB for ; Fri, 11 Mar 2016 08:08:37 +0000 (UTC) Received: from mbob.nabble.com (mbob.nabble.com [162.253.133.15]) by mx2-lw-us.apache.org (ASF Mail Server at mx2-lw-us.apache.org) with ESMTP id 1E1925FACB for ; Fri, 11 Mar 2016 08:08:37 +0000 (UTC) Received: from msam.nabble.com (unknown [162.253.133.85]) by mbob.nabble.com (Postfix) with ESMTP id 1E93622B0F14 for ; Thu, 10 Mar 2016 23:59:28 -0800 (PST) Date: Fri, 11 Mar 2016 01:08:36 -0700 (MST) From: bartoleo To: users@groovy.incubator.apache.org Message-ID: In-Reply-To: <56E24D6E.5010800@apache.org> References: <56E24D6E.5010800@apache.org> Subject: Re: XML node access by variable MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_639201_1309277629.1457683716102" ------=_Part_639201_1309277629.1457683716102 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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] < ml-node+s329449n5731831h32@n5.nabble.com>: > I'm using XML Slurper to parse an XML file with this type of format: > > > ... > ... > ... > > > ... > ... > ... > > ... > > The XML file node names are constantly changing so I would like to use a > variable for the node designations. > > defreport =3DnewXmlSlurper().parse(myXmlFile) > > instead of access the C1 node like: > report.R.each() {item -> > item.C1 > } > > I'm using: > def myTag =3D "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 > ml-node+s329449n329450h21@n5.nabble.com > To unsubscribe from Groovy, click here > > . > NAML > > --=20 Leo Bartoloni ---------------------------------------------------------------------------= ---------------------------------------------------------------------------= ----- Qualsiasi utilizzo non autorizzato del presente messaggio e dei suoi allegati =C3=A8 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=C3=A0 e/o alla missione aziendale. si intendono non attribuibili alla societ=C3=A0 st= essa, n=C3=A9 la impegnano in alcun modo. -- View this message in context: http://groovy.329449.n5.nabble.com/XML-node-a= ccess-by-variable-tp5731831p5731833.html Sent from the Groovy Users mailing list archive at Nabble.com. ------=_Part_639201_1309277629.1457683716102 Content-Type: text/html; charset=UTF8 Content-Transfer-Encoding: quoted-printable
One way is using 'index notation':

<= div>
report.R.each {item ->=C2=A0
=C2=A0 println item[myTa= g]
}

or GString
report.R.each = {item ->=C2=A0
=C2=A0 println item."$myTag"
}

report.R."$myTag".each {item ->= =C2=A0
=C2=A0 println item
}=C2=A0

=
Leo

2016-03-11 5:46 GMT+01:00 Carl Marcum [via Groovy] <[hidden email]>:
=09I'm using XML Slurper to parse an XML file with this type of format:

<R>
=C2=A0 =C2=A0<C0>...</C0>
=C2=A0 =C2=A0<C1>...</C1>
=C2=A0 =C2=A0<C2>...</C2>
</R>
=C2=A0 <R>
=C2=A0 =C2=A0<C0>...</C0>
=C2=A0 =C2=A0<C1>...</C1>
=C2=A0 =C2=A0<C2>...</C2>
</R>
...

The XML file node names are constantly changing so I would like to = use a=20
variable for the node designations.

defreport =3DnewXmlSlurper().parse(myXmlFile)

instead of access the C1 node like:
report.R.each() {item ->
item.C1
}

I'm using:
def myTag =3D "C1"
report.R.each {item ->
item.getProperty(myTag)
}

Is there a shorter way to access the node by variable without=20
getProperty(tagVar)?

Thanks,
Carl Marcum
Apache OpenOffice committer and PMC

=09 =09 =09 =09
=09
=09

=09
=09=09
If you reply to this email, your mess= age will be added to the discussion below:
=09=09h= ttp://groovy.329449.n5.nabble.com/XML-node-access-by-variable-tp5731831.htm= l =09
=09
=09=09To start a new topic under Groovy Users, email [hidden email]
=09=09To unsubscribe from Groovy, click here.
=09=09NAML =09



--
Leo Bartoloni

----= ---------------------------------------------------------------------------= ---------------------------------------------------------------------------= -
Qualsiasi utilizzo non autorizzato del presente messaggio e dei suoi a= llegati =C3=A8 vietato e potrebbe costituire reato.
Se lei avesse ricevu= to erroneamente questo messaggio, Le saremmo grati se provvedesse alla dist= ruzione dello stesso
e degli eventuali allegati.
Opinioni, conclusion= i o altre informazioni riportate nella e-mail, che non siano relative alle = attivit=C3=A0 e/o
alla missione aziendale. si intendono non attribuibili= alla societ=C3=A0 stessa, n=C3=A9 la impegnano in alcun modo.
=09 =09 =09

View this message in context: Re: XML node access by= variable
Sent from the Groovy Users mailing list archive at Nabble.com.
------=_Part_639201_1309277629.1457683716102--