[jdom-interest] Namespace.hashcode patch

Ken Rune Helland kenh at csc.no
Thu May 31 03:33:20 PDT 2001

At 09:19 PM 5/30/2001 -0500, Bryan Thale wrote:
>I apologize if this has been beaten to death before, but doesn't this tend to
>indicate that the marriage between prefix and URI is a little too tight?  The
>relationship between prefix and URI is many to one, not the one to one the 
>class seems to represent.  Would a better approach be to use two 
>maps?  One mapping
>prefix -> Namespace and one mapping URI -> Namespace?  Actually, I think 
>one map
>would do since prefixes can't contain colons or slashes and would thus 
>always be
>distinguishable from URIs as keys so both sets of mappings could be stored 
>in the
>same HashMap.  getAdditionalNamespaces() could return a list of prefixes 
>instead of
>Namespaces.  Prefixes could be removed from such a list with impunity and 
>accuracy.  Isn't that what remove(Namespace("foo","http://foo")) actually 
>that you're removing the prefix, not necessarily the namespace from the 
>That's probably too much work at this stage.  Could we make .equals() mean 
>== again
>and add a .matches() or a .equalsIgnorePrefix() or something to the Namespace
>interface to test for "xml equality"?  It's a kludge but it would work and not
>impact the rest of JDOM much.

When I read an XML i generally dont care what prefix an element or attribute
have, only what namespace it is in.

But when I create an Element or attribute I may want to controll
what prefix this element or attribute is using to denote its namespace.

So when creating a Element or attribute I shoud be able to give inn a Namespace
for the element saying i dont really care about the prefix as long as
the element/attribute is in this namespace, or give inn a prefix pluss 
saying I want this namespace to be denoted by this prefix in this 

In the first case maybe the outputters shoud look for declarations
of the namespace higher in the tree and just pick a prefix already
maped to this namespace, or if this is the default namespace at this
point not add a prefix att all. If there is no prefix declared for
this namespace this will eiter be an errorcase or the outputter
creates an unused prefix "P1, P2 ..." for the namspace and adds
namespace declaration using this prefix.

In the second case simply output the prefix and if the prefix is
not already declared to this namespace delcare it.

I think we somehow need a NamespacePrefix class so we can
separate a namespace from its prefix when creating documents.

public class NamespacePrefix{
    private String prefix;
    private Namespace namespace;


    public static NamespacePrefix getInstance(String prefix, Namespace 

    public static NamespacePrefix getInstance(String prefix, String URI)

Probaly it shoud be modeled after namespaces
by being imutable and having private constructors
and a static public getInstance metod that interns
all instances to conserve memory.

I guess it will take some work to integrate someting like this
and it will probaly breake old code using namespaces but we shoud
have a good namespace model before v1.0.


More information about the jdom-interest mailing list