ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steve Loughran <>
Subject Re: QName in DynamicAttributeNS
Date Wed, 14 Jun 2006 12:19:29 GMT
Dominique Devienne wrote:
> On 6/13/06, Peter Reilly <> wrote:
>> The prefix for elements (as against attributes) are retained.
>> ProjectHelper2 called UE.setQName(qName) with the
>> name it receives from the sax.

aah. this explains why I had got echoxml to work doing namespaced stuff.

>> Something needs to be done for attributes..
> Namespaces are used to avoid name collision, and in Ant to locate the
> right implementation class. That's necessary for top-level tasks, and
> for nested elements in tasks/types having add(Xyx) methods.
> Attributes in Ant OTOH, are always "resolved" relative to their
> element. Their can't be any ambiguity ATM for attribute. Ant doesn't
> support namespace'd attribute at all, AFAIK.

oh, it does, sort of. If you have a task to build qnames of all 
attributes passed in and print them out, this is what you see

1.  ("",attributes)  map to simple attributes

  <book:ex test="true") calls setAttributeNS("","test",something,"true");

   <target name="showDynaTaskBookNamespace" depends="define">
     <book:dynatask username="erik" />
       <au:logcontains text="{}" />
     <au:assertLogContains text="username" />

2. stuff in a different namespace comes down with that namespace

   <target name="testDynaTaskAntunitNamespace" depends="define">
     <book:dynatask au:username="erik" au:hostname="localhost"/>
     <au:assertLogContains text="{antlib:org.apache.ant.antunit}hostname" />
     <au:assertLogContains text="{antlib:org.apache.ant.antunit}username"/>

2. ("prefix",attributes) map to simple attributes if the uri of the 
parent element==uri of prefix

This holds for matching prefix

   <target name="showDynaTaskBookNamespace" depends="define">
     <book:dynatask au:username="erik" au:hostname="localhost"/>
       <au:logcontains text="{}" />
     <au:assertLogContains text="{antlib:org.apache.ant.antunit}hostname" />

And for matching URI, different prefix

   <target name="testDynaTaskB2Namespace" depends="define">
     <book:dynatask b2:username="erik"
       <au:logcontains text="{}"/>

3. Stuff that matches an introspection attribute binds first

   <target name="testDynaTaskBookStandardAttribute" depends="define">
     <book:dynatask description="unknown" />
       <au:logcontains text="description"/>

4. If you have a localname prefix and something in the same namespace as 
the container, whatever attribute is reached last seems to win:

   <target name="testDynaTaskDuplicates" depends="define">
     <book:dynatask book:attr="one" attr="two"/>
       <au:logcontains text="one"/>

#4 is a bit problematic as it violates XML's one attribute of a 
(uri,localname) tuple per element rule. You could even, maybe, do bad 
things to ant tasks that assume their setAttribute call gets made once 
per task. The only way to stop it would be to track attributes set on an 
element, and bail if a second attempt to set one was made during 

> Also, remember that attributes don't inherit the namespace of their
> element, and are always in the "" namespace, unless explicitly
> qualified with a prefix. As I write above, Ant doesn't support them
> for introspected class.
> Using namespace prefixes is dangerous, because they can change from
> element to element, depending on while namespaces are in scope, and we
> can have different prefixes for the same NS URI, or the same prefix
> for different NS URIs depending on the element (although this is evil,
> XML supports it).

it may be evil, but is often needed.  It lets you declare stuff in a new 
namespace without knowing every single xmlns declaration in ther rest of 
the doc, or even that there is another doc.

> XmlFragment is already not "exact" XML, as all text nodes, even with
> nested element in between them, are merged together. I'm not sure it's
> worth it to be exact XML... --DD

It doesnt do PIs either. If you really want low level stuff, <echo>CDATA 
works, but I'd like xmlns support to be improved, for anything that uses 
DynamicAttributeNS, otherwise the method isnt that useful.


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

View raw message