ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Igor Peshansky <ig...@us.ibm.com>
Subject Re: QName in DynamicAttributeNS
Date Tue, 13 Jun 2006 17:23:17 GMT
Peter,

You just got lucky because d.e.f is a valid XML name.  If you try a full
URL (e.g., "http://d.e.f"), you'll get a nasty exception.

Technically, DOM keeps the actual namespace URI for all attributes, so
if ant keeps the prefix for all the elements, you can probably look up
the appropriate prefix for a given namespace.  However, if some esoteric
namespace is used for all attributes that is different from that of any
element, you'll need to do more work to keep the attribute prefix
around.
        Igor

"Peter Reilly" wrote on 06/13/2006 01:05:46 PM:

> I guess that it only got exercises with simple examples:
> 
> I tried the echoxml:
> <project xmlns:abc="a.b.c" xmlns:def="d.e.f">
>     <echoxml>
>         <abc:hello  abc:a="abc" def:b="def">
>           world
>         </abc:hello>
>     </echoxml>
> </project>
> 
> and got:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <abc:hello a="abc" d.e.f:b="def">world</abc:hello>
> 
> Which has two problems
>   1 no mapping of prefix to uri
>   2 def:b gets reformed as d.e.f:b
> 
> Peter
> On 6/13/06, Igor Peshansky <igorp@us.ibm.com> wrote:
> >
> > Steve Loughran wrote on 06/13/2006 06:24:45 AM:
> >
> > > I'm now looking at the namespace aware dynamic attribute stuff
> > >
> > > The qname parameter for this is built up as follows:
> > >                  String qName = ("".equals(uri)
> > >                                  ? localName : (uri + ":" + 
localName));
> > >
> > >
> > > this is not how, say, Qname.toString() presents qnames, which is
> > > {http://example.org}tag
> > >
> > > I'd change it, but then I looked at how XmlFragment handled it, 
which it
> >
> > > does by handing it off to the Dom element
> > >
> > >                  e.setAttributeNS(uri, qName, value);
> > >
> > > I dont use classic DOM. but from what the javadocs imply, this 
appears
> > > wrong. the qname that Element.setAttributeNS() seems to want is a
> > > classic prefix:value tuple, like "xmlns:name" or "ant:example".
> > >
> > > So really we should pass down the prefix and localname, as the uri 
comes
> >
> > > down in the namespace URI param:
> > >
> > >                  String qName = ("".equals(uri)
> > >                                  ? localName : (prefix + ":" +
> > localName));
> > >
> > > Am I right here? This is not shipping code so we have time to 
correct
> > > it, but I'd need input from someone who knows Dom intimately enough 
to
> > > get it right. Me, I use Xom :)
> > >
> > > -steve
> >
> > Steve,
> >
> > Yes, you are correct.  The prefix value is not used when serializing
> > and/or
> > comparing QNames.  The setAttributeNS method extracts the prefix part 
from
> > the qName parameter and sets it on the Attr node (whether new or
> > existing).
> > The prefix is optional -- you should be able to simply pass the 
localName
> > in, independent of whether the namespace is present.
> >
> > What I'm surprised at is that not only is this not shipping code, this
> > code
> > is apparently not exercised at all, since the two implementations I 
looked
> > at will throw an exception if you try to use the URI as the prefix in 
the
> > way that the code you quoted does.
> >         Igor

-- 
Igor Peshansky  (note the spelling change!)
IBM T.J. Watson Research Center
XJ: No More Pain for XML's Gain (http://www.research.ibm.com/xj/)


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message