[jdom-interest] Re: Radical Suggestion

Dennis Sosnoski dms at sosnoski.com
Sun Jul 28 20:40:32 PDT 2002

Elliotte Rusty Harold wrote:

>> That's true, accessing elements potentially gets really awkward when 
>> you're dealing with arbitrary documents that have been read in. So 
>> what could be done to simplify namespace handling for developers? 
>> Maybe a way of creating an element without an explicit namespace 
>> would help, where the element would assume the default namespace of 
>> whereever it was put into the document.
> Why would you ever want to do this? You're asking to allow somebody to 
> take an XHTML table element, move it to a different part of the 
> document, and have it magically morph into an XSL-FO table element, 
> just because the namespace mappings in that section of the document 
> are different. <snip> 

Actually, I'm not asking this at all. What I'm suggesting is modeling 
what happens when you add or move elements around with a text editor, 
for instance. The default namespace in effect at the point you insert 
the elements automatically applies to the added elements. Here again, 
the only reason for suggesting this is that it appears to be what most 
developers expect to have happen. Namespace knowledgeable developers 
could continue to use explicit namespaces for every element, if that's 
what they wanted to do.

>> For the access side, maybe what would really help would be easy ways 
>> of accessing elements and attributes by local name while ignoring 
>> their namespaces. I realize that from the XML POV this is a horrible 
>> idea, but it suits what most developers are doing most of the time. 
>> <snip> It also reflects the way XML is actually used - cases where 
>> child elements can have the same local name but different namespaces 
>> are exceedingly rare in practice, as far as I've ever seen.
> Not as uncommon as you might think. There are lots of mutual conflicts 
> between XHTML, XSL-FO, SVG, RDF, MathML, etc.: table, set, a, text, 
> style, script are just some of the elements that appear in more than 
> one of these. 

I'm not familiar with XSL-FO, so I can't comment on that. The rest of 
these examples seem to miss my point. Yes, the same element names are 
definitely used in different XML applications. However, the cases where 
a particular type of parent element can validly have child elements 
distinguished only by namespace are much rarer. Very few applications do 

    <myns:table .../>
    <hisns:table .../>
    <herns:table .../>

Being able to find children by local name only would make the 99%+ case 
easier, without making the 1%- case any harder.

In cases where you're searching through different levels of the document 
tree to find a particular name conflicts between namespaces would be 
more common. JDOM doesn't provide any APIs that directly support this, 
though - the only way of doing it is with XPath, which has its own set 
of namespace issues.

  - Dennis

More information about the jdom-interest mailing list