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

philip.nelson at omniresources.com philip.nelson at omniresources.com
Wed Aug 29 09:11:06 PDT 2001


> But, a "" namespace is illegal per w3c DOM.

It is perfectly legal and means, not in any namespace.  Check out the spec
at the w3c

> I have created XML with other tools and they do not do this.  When you
> assign xmlns="http://www.someplace.com" all it's children are 
> part of that
> namespace unless you explicitly say other wise.  So when I 
> set the root
> element to xmlns="http://www.someplace.com" all it children 
> are in that
> namespace, so for JDOM to add to the first level children an illegal
> namespace of "" this file is now invalid when I try to convert a JDOM
> document to a w3c DOM Document an exception is thrown stating 
> that "" is
> illegal for a namespace.  

You are thinking of the text representation of an xml document.  When you
physically look at a stored document, you see a parent element with a
namespace.  You imply that to mean that the children are "in the parents
namespace". JDOM does exactly the same thing when it reads an xml document
from storage, it puts the child elements in the namespace of the parents.
When you create an element yourself in code, you also must tell it what
namespace the element is in.  If you don't, it is in the no namespace
namespace with uri="".  

Really, it's easier than you think.  Create the parent element with a
namespace and then use the overloaded constructors for the children that
take namespace objects, and pass the parents namespace.


> 
> I should NOT have to assign a namespace to every element.  I 
> am creating XML
> files that must be validated against a Schema and the schema 
> works as I
> stated, that all children are in the same namespace as the 
> parent unless
> explicitly changed.
> 
> -----Original Message-----
> From: philip.nelson at omniresources.com
> [mailto:philip.nelson at omniresources.com]
> Sent: Wednesday, August 29, 2001 8:37 AM
> To: rsfoley at harddollar.com; jdom-interest at jdom.org
> Subject: RE: [jdom-interest] xmlns="" in children elements of root
> 
> 
> 
> > I tried this with the beta 7 binaries, and also downloaded 
> the source
> > yesterday (8-28-01) afternoon and have the same problem.
> > 
> > When I give my root element (using XMLOutputter) a namespace of just
> > "xmlns=http://www.someplace.com" I do not explicitly assign a 
> > namespace to
> > any of the children elements at any level, but the first 
> > level children of
> > the root are assigned a namespace of 'xmlns=""' which I can 
> > not figure out
> > why and can not get ride of it.  This should not be happening 
> > and makes it
> > invalid against the schema.  
> 
> You *must* assign the namespace to each element you create.  
> A child element
> does not automagically get the parents namespace which means 
> it is in the ""
> namespace.  This is by design and was *HEAVILY* discussed here.
> 



More information about the jdom-interest mailing list