Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse a xml by ANT

Tags:

xml

ant

trying to build a project set file and checkout these projects:

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

now I need extract 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 to each token on each line:

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

Can someone help me with this? thanks

like image 308
Tom Avatar asked Feb 26 '10 19:02

Tom


People also ask

How do I run an Ant file in XML?

To run the ant build file, open up command prompt and navigate to the folder, where the build. xml resides, and then type ant info. You could also type ant instead. Both will work,because info is the default target in the build file.

What is parsing an XML?

Definition. XML parsing is the process of reading an XML document and providing an interface to the user application for accessing the document. An XML parser is a software apparatus that accomplishes such tasks.

What is Ant XML?

Ant is a Java-based build tool created as part of the Apache open-source project. You can think of it as a Java version of make. Ant scripts have a structure and are written in XML. Similar to make, Ant targets can depend on other targets. For example, Ant is used in the context of plug-in development in the build.


1 Answers

I've used this http://www.oopsconsultancy.com/software/xmltask/ in the past to process XML with ANT. I threw together a quick sample 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 does work to get the attribute values individually.

like image 170
karoberts Avatar answered Oct 15 '22 10:10

karoberts