Reputation: 19133
I have the following XML file. I was able to read it using the xmlParser class.
def records = new XmlParser().parseText(xml)
I don't know how to extract the row attributes and value. Here is the XML:
<?xml version='1.0' encoding='UTF-8'?>
<dataSet>
<info>
<name>test xml</name>
</info>
<columns>
<column name="subject" description="subject name" type="xs:string" maxLen="300" nillable="true" />
<column name="rankid" description="Rank" type="xs:string" maxLen="30" nillable="true" />
</columns>
<data>
<row>
<column name="subject">English</column>
<column name="rankid">3</column>
</row>
<row>
<column name="subject">Computer</column>
<column name="rankid">4</column>
</row>
</data>
</dataSet>
I want this output:
English,3
Coputer,4
Can you help me do this in groovy?
Upvotes: 0
Views: 604
Reputation: 171154
Does
def data = records.data.row.collect {
it.column*.text()
}
Work?
Upvotes: 2