ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Wannheden, Knut" <>
Subject RE: NameSpace & antlib was (Re: polymorphism)
Date Tue, 29 Apr 2003 08:21:26 GMT
> peter reilly wrote:
> > True. It seems quite difficult to use namespaces in a nice way.
> You are not supposed to "use namespaces in a nice way".
> XML Namespaces are there so that you can avoid name clashes
> for XML element and attribute names if you want to use XML
> vocabularies from various uncoordinated sources together.
> XML Namespaces do *not* have the purpose of
> - link to a web page
> - point to a library/jar
> - link to whatever ressource.
> While even "names" from W3C TCs obviously commited such abberations,
> this doesn not mean it is good style. In fact, abusing XML namespaces
> for other purposes than disambiguating short element and attribute
> names has brought unnecessary difficulties into XML processing,
> and many of the people formerly advocating such uses are now
> regretting it.

Nicely put.  Reflects my thoughts on the topic exactly.

> > The niceest I can thing of is to place all the jars in
> > ${ant.home}/lib and set the namespace up in the project declation:
> > 
> > <project xmlns:antcontrib="antlib:${ant.home}/lib/ant-contrib.jar"
> >              xmlns:antcontrib="antlib:${ant.home}/lib/antleope.jar">
> This is not only utter foolishness: it would mean the semantic
> of an XML element in the namespace the antcontrib prefix points
> to would change if ant.home changes, beside other problems. It
> has the additional problem of being syntactically invalid: you
> must not declare the same namespace prefix twice on the same
> element.

Further, I don't think having property resolution in the namespace URI is a
good idea at all.  That opens up a big can of worms.  For instance: when
comparing namespace URIs for equality do you compare the property-resolved
URIs or the URIs as is?  According to the namespace spec it is clear that
namespace names are compared character by character
(  The following document
is not valid:

<x xmlns:n1="" 
   xmlns:n2="" >
  <bad n1:a="1"  n2:a="2"/>

because <bad/> has two attributes with local name "a" which both are bound
to the same namespace name.  But would the following be legal in Ant?

<target xmlns:n1="antlib:${ant.home}/lib/x.jar"
 <bad n1:a="1" n2:a="2"/>

(I'm asking this question regardless of whether attributes with a namespace
have any meaning in Ant or not.)  The XML parser would surely not complain.

Further the URI declarations wouldn't be portable because the property
resolution would depend on the processing context of Ant.  I would only be
able to tell if two namespace declarations reference the same namespace by
executing the actual buildfile.  E.g.

<target xmlns:n1="antlib:${ant.home}/lib/foo.jar">
 <property name="foo.jar" location="${ant.home}/lib/foo.jar"/>
 <bar xmlns="antlib:${foo.jar}"/>

The question I think is more important is whether antlibs should be loaded
explicitly with something like an <antlib/> task (similar to <taskdef/>) or
if it should be more automagical like in Jelly where the namespace name is
parsed (e.g. xmlns:j="jelly:core" or xmlns:my="").
(Jelly actually allows both.)  I am clearly in favor of requiring explicit
loading with a designated task.



  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message