[jdom-interest] Re: Radical Suggestion

Elliotte Rusty Harold elharo at metalab.unc.edu
Mon Jul 29 05:37:27 PDT 2002

At 8:40 PM -0700 7/28/02, Dennis Sosnoski wrote:

>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.

What about the developers who need to mix non-namespaced and 
namespaced elements in the same document? This occurs in DocBook 4.2, 
for example, and in many, many, XSLT stylesheets.

JDOM must work primarily for developers who understand XML and 
namespaces. Developers who do not understand XML and namespaces may 
have trouble, but this is not our fault. Furthermore, we would be 
doing such developers an intense disservice by allowing them to 
remain confused and misguided, rather than letting them know that 
they have a problem. JDOM, like all good APIs, is designed for 
non-domain-experts by domain experts. The users are relying on us to 
produce an accurate model of XML. We know how namespaces work. It is 
our responsibility to package that knowledge in a form that can be 
used by programmers who are less sure.

>>>  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.

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

Think descendants rather than just children. However, the biggest 
problem is that this makes everything harder because it confuses 
JDOM's API. Right now JDOM has a very simple story: to do anything 
with anything in a namespace provide the namespace URI and the local 
name. You're proposing to start breaking that up into special cases, 
where over here we use a URI and a local name but over there you just 
use a local name. Consistency is a large contributor to simplicity.

>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.

It can and is done in JDOM through tree walking which involves a lot 
of calls to getChildElements() or getContent() and so forth. XPath is 
not required.

| Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
|          XML in a  Nutshell, 2nd Edition (O'Reilly, 2002)          |
|              http://www.cafeconleche.org/books/xian2/              |
|  http://www.amazon.com/exec/obidos/ISBN%3D0596002920/cafeaulaitA/  |
|  Read Cafe au Lait for Java News:  http://www.cafeaulait.org/      |
|  Read Cafe con Leche for XML News: http://www.cafeconleche.org/    |

More information about the jdom-interest mailing list