ant-user mailing list archives

Bill,
You can't have the same attribute twice in an element in XML. To do what
you want, you will need to create nested elements
<mytask>
<myAttr value="foo"/>
<myAttr value="bar"/>
</mytask>
This arrangement is supported by Ant's introspection. You will need a
createMyAttr() method which returns an instance of a class (typically this
could be an innerclass of mytask) which accepts the value attribute (i.e.
setValue(String ) method). The createMyAttr() method would store the nested
element instances as they are created in a vector. When your task is ready
to execute it can pull all of the myAttr values out of the vector and
combine them. Other combinations are also possible such as
<mytask>
<myAttr>foo</myAttr>
<myAttr>bar</myAttr>
</mytask>
for which you would use the addText method in your myAttr class.
Check the createLink method in Javadoc.java for an example of this in
operation.
Conor
----- Original Message -----
From: <Bill.J.Fellows@mail.sprint.com>
To: <ant-user@jakarta.apache.org>
Sent: Tuesday, May 01, 2001 8:57 AM
Subject: Adding tasks
> Howdy,
>
> Is it possible to do something like this when defining my own task? If
> so, anyone care to point me in the right direction?
>
> <mytask myAttr="foo" myAttr="bar" myAttr="blee">
>
> This gives me an error about "myAttr" already appearing in this tag.
> I'd like to be able to append all these attributes together like this.
>
> public void getAttr(String attr) {
> if (this.attr == null)
> this.attr = "";
> this.attr += attr;
> }
>
> Any thoughts, suggestions, places to look, et cetera, would be much
> appreciated.
>
> /bill
>