How to parse xml using ANT

trying to create a project set file and validate these projects:

<psf>
  <project ref="version,url,name"/>
  <project ref="version,url,name"/>
  <project ref="version,url,name"/>
</psf>

now I need to extract the url and name from each project tag. I used

<xmlproperty file="example.psf" collapseAttributes="true" />

but when I

<echo>$psf.project.ref</echo>,

I got something like this, instead of having control over every token on every line:

version,url,name,version,url,name,version,url,name

Can someone help me? thank

+5
source share
1 answer

I have used this http://www.oopsconsultancy.com/software/xmltask/ in the past to process XML using ANT. I put together a quick example of getting each individual attribute.

    <taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask"/>
    <xmltask source="test.xml">
        <call path="psf/project">
            <param name="ref" path="@ref"/>
            <actions>
                <echo>ref = @{ref}</echo>
            </actions>
        </call>
    </xmltask>

Not sure if this will suit your needs, but it works to get the attribute values ​​individually.

+9
source

All Articles