Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] XPath Namespace Nodes rethink

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Elliotte Harold <elharo AT metalab.unc.edu>
  • To: Michael Kay <mike AT saxonica.com>
  • Cc: 'xom-interest' <xom-interest AT lists.ibiblio.org>
  • Subject: Re: [XOM-interest] XPath Namespace Nodes rethink
  • Date: Mon, 31 Jan 2005 19:57:51 -0500

Michael Kay wrote:


Modelling "inscope namespaces" rather than "declared namespaces" gives much
more predictable results from a user perspective: when elements are
disconnected from a tree and added to another tree, they take all their
inscope namespaces with them.

Consider what happens when you do this:

Element a = new Element("pre:a", "http://www.example.com/";);
Element b = new Element("b", "http://www.example.org";);
a.appendChild(b);

What namespaces are in scope for b now? Is the pre namespace mapped or not? The logical thing is to assume that, no, the pre prefix is undeclared, except you can't do that in XML 1.0.

Now suppose we disconnect b and add it to c:

b.detach();
Element c = new Element("foo:c", "http://www.somewhere.com";);
c.appendChild(b);

Does it still have the namespaces it had when it was attached to b? Does it lose all those namespaces when it's detached? If so, why? If not, what happens when you do this:


b.detach();
Element d = new Element("foo:d", "http://www.somewhere_else.com";);
d.appendChild(b);

Now the foo prefix has been remapped, but only because it conflicted. Otherwise it wouldn't have been.

No matter how you slice it, you end up with these weird corner cases. XSLT, XPath, and DOM work with this, barely, because they never move a node from one document to another. They create new nodes, but don't rearrange existing nodes. That causes problems and limitations of its own. XOM does move nodes from one document to another, and in so doing bends XML namespaces just far enough to break them.

--
Elliotte Rusty Harold elharo AT metalab.unc.edu
XML in a Nutshell 3rd Edition Just Published!
http://www.cafeconleche.org/books/xian3/
http://www.amazon.com/exec/obidos/ISBN=0596007647/cafeaulaitA/ref=nosim




Archive powered by MHonArc 2.6.24.

Top of Page