[jdom-interest] xmlns="" in children elements of root

Rodney S. Foley rsfoley at harddollar.com
Wed Aug 29 11:09:52 PDT 2001


Look at the example in JDOM's own FAQ: "Why do I need to pass in a Namespace
to getChild(), when the child element I'm looking for has no namespace
declaration?"

Where this:
<x>
  <y xmlns="http://foo.com">
    <z />
  </y>
</x>

And this:
<x>
  <y xmlns="http://foo.com">
    <z xmlns="http://foo.com" />
  </y>
</x>

Are the same.  The XML text file does not NEED to display the child's
namespace because it is inherited from the parent if none is specified.  If
I were to CUT and PASTE that element that does not have a namespace under a
different parent it would then have the same namespace as it's new parent.
This is how XML is read.  Why can't we write an XML file the same from our
CODE.

If I am adding an elements to another element in my code I know that it is
going to have the same namespace as it's parent if I do not give it one.
Also if I move the element around in my code and I never gave it a namespace
I would expect it to have the same namespace as it's new parent.

I think coding with any API should be as intuitive as possible. 

Where this:

Namespace ns = Namespace.getNamespace("http://foo.com");
Element y = new Element("y", ns);
x.addContent(y);
Element z = new Element("z", ns);
y.addContent(z);

And this:

Namespace ns = Namespace.getNamespace("http://foo.com");
Element y = new Element("y", ns);
x.addContent(y);
Element z = new Element("z");
y.addContent(z);

Are the same. Because that is intuitive to anyone who knows how to READ or
create from scratch an XML File.


-----Original Message-----
From: Jason Hunter [mailto:jhunter at collab.net]
Sent: Wednesday, August 29, 2001 10:50 AM
To: Rodney S. Foley
Cc: ; 'philip.nelson at omniresources.com'
Subject: Re: [jdom-interest] xmlns="" in children elements of root


"Rodney S. Foley" wrote:
> 
> I would purpose that JDOM check every time an element(a) is added to
another
> element(a) that element(a) checks for element(b)'s namespace.  If none was
> set, then element(a) give's element(b) it's namespace, and set's a flag on
> element(b) stating namespace was automatically set.

Eww, that's awful.  Explicitly not having a namespace is as much a
differentiator as being in a specific namespace.  In fact, such elements
do have a Namespace, the NO_NAMESPACE constant.

You do not want to auto-put an element in a namespace because of its
parent, or have an elt's namespace change later because it is moved.

-jh-



More information about the jdom-interest mailing list