Radical Suggestion (was Re: Antwort: RE: [jdom-interest] Namespace help)

Michael Salmon ms at formulae.org
Thu Jul 25 13:20:30 PDT 2002

Another idea about handling creating elements that inherit namespaces
from their parent. It would be possible to add a method
public Element makeChildElement(String name, etc..) in Element itself which 
would do a few things.
1) copy the existing elements namespace into this new element.
2) add the element as a child element to this element

Element root = new Element("root", "foo");
childOrderA = root.makeChild("A");
childOrderB = childOrderB.makeChild("B", "bar");

would create xml like:
<root xmlns="foo">
  <A xmlns="foo">
    <B xmlns="bar"/>


On Thu, Jul 25, 2002 at 10:43:11AM -0700, Dennis Sosnoski wrote:
> Namespace handling is an especially messy issue for developers, judging 
> from the number of times this misunderstanding occurs with all the 
> document models. The problem is that XML defines each element as having 
> a definite namespace (even if it's the "no namespace" namespace), but 
> from a programmer's point of view it's more natural to see things in 
> terms of namespace inheritance through the tree structure - an element 
> either has an explicit namespace denoted by a prefix or default 
> namespace definition, or is in the default namespace defined by an ancestor.
> If JDOM's goal is ease of use it seems like matching the programmer's 
> POV rather than the XML POV would be the right way to go. What this 
> would probably mean is that elements created without a specified 
> namespace would just inherit the default namespace determined by where 
> they were linked into the tree. The namespace could still be set 
> explicitly if desired, and it'd be easy enough to extract and set the 
> namespace when removing an element (and children) from a tree, again if 
> desired.
> I think this has been discussed before. The fact that it keeps popping 
> up as a source of confusion for users says that the current scheme 
> (which is the same as DOM, dom4j, and all the other document models) 
> doesn't work well for programmers.
>  - Dennis
> Li Xu wrote:
> >Bob and Ken
> >
> >Thank you!!! You answered my vague question clearly here.
> >
> >I thought when I assign a namespace using setNamespace() in an element, all 
> >its existing children will "by default" get it if they don't have a NS yet. 
> >Ken hit my nail in the head that I was using the string representation 
> >logic to assume the inheritance among the actual java objects.
> >
> >Cheers all!
> >LX
> >_______________________________________________
> >To control your jdom-interest membership:
> >http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com
> >
> > 
> >
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com

More information about the jdom-interest mailing list