ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nicola Ken Barozzi <>
Subject Re: Read repetitive tags as properties from an XML file
Date Tue, 27 Aug 2002 18:13:43 GMT

Simon Baker wrote:
> Hi Nicola
> Thanks for the patch. Some further questions:

                  :-)                  :-)

> 1. Do i need to try it out before it gets into a nightly build?

Ahem... it's a patch, not yet in CVS.
You can try it out before if you need it.

> 2. I've examined the source and was wondering what will happen to the
> following XML:
> <root>
> <a atr="tag1">
> 	<b> one </b>
> 	<b> two </b>
> </a>
> <a atr="tag2">
> 	<b> three </b>
> 	<b> four </b>
> </a>
> </root>
> If I understand the XMLProperty documentation the attribute value does not
> influence the ant property name. 


> Solutions?
> ------------------
> 1. Maybe XMLProperty can have setting where attribute value does influence
> property name. For instance the above example could translate into:
> root.a.atr=tag1,tag2
> root.a.atr_tag1.b=one,two
> root.a.atr_tag2.b=three,four
> root.a.b=?maybe? one,two,three,four

hehehe, very tricky, I didn't think of it ;-D

Currently, without testing, the patch I submitted should give with 


With collapseAttributes=false:


Now, what you want to do is something like



> 2. Maybe a simple XPath like task would be more appropriate.
> Any thoughts/advice?

Already done :-)

It's called JXpath and XMLDOM, and you find them in the dir proposal/embed.

Just cd in that dir, run Ant, and it will automatically install the 
extension in your Ant (copies simply sax2.jar in you ANT_HOME/lib dir).

Then, to do what you need:

     <taskdef classname=""
              name="jxpath" />

     <!-- Init JxPath. '/' is the project -->

     <!-- This is - a datatype that holds an xml DOM  -->
     <typedef name="xmldom"

    <!-- Init XMLDOM.The DOM of the file will be referenced via the id-->
     <xmldom id="mypros" file="properties.xml"/>

  <echo message="${jxpath:/references/mypros/root/root/a[atr=tag1]/b}" />

For more info:

Nicola Ken Barozzi         
             - verba volant, scripta manent -
    (discussions get forgotten, just code remains)

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message