groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Carl Marcum <cmar...@apache.org>
Subject XML node access by variable
Date Fri, 11 Mar 2016 04:45:34 GMT
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


Mime
View raw message