Re: XML APIs

Stephen R. Savitzky wrote:

> Simple iterators that keep track of the current node and perform a
> depth-first left-to-right traversal [...] behave
> _predictably_ when the tree is modified during an iteration; whether this
> behavior is ``correct'' or not depends entirely on what the programmer has
> been led to expect.

I'm not sure I understand the meaning of "correct" vs. "predictable"
here.  If the implementation is understood to be single-threaded, then
all behaviors are "predictable" no matter how bizarre, since none of
the node operations do arbitrary computation.  But even under a single-
threaded interpretation, various "obvious identities" do not hold:

	(leftSibling(rightSibling(node)) = node,
		unless node is a lastChild;
	(rightSibling(leftSibling(node)) = node,
		unless node is a firstChild;
	(firstChild(parent(node)) = node,
		if node is a firstChild;
	(lastChild(parent(node)) = node,
		if node is a lastChild;
	(rightSibling(firstChild(node)) = 2nd child of node
		provided there is one,
	the algorithm "go to firstChild if there is one, otherwise
	to rightSibling if there is one, otherwise to parent's
	(grandparent's (great-grandparents (etc.))) rightSibling
	until you reach the starting point" walks the descendants.

etc. etc. etc.  All of these are false under the DOM.

> At this point I'm probably going to stop hoping that iterators get back into
> the DOM at some point, and instead count on programmers to design
> appropriate classes of their own that don't depend on whatever bizarre
> single-application-specific behavior somebody decides to throw into the spec
> because they think they know better than I do what my application wants to
> do with a parse tree.

The difficulty is that the DOM is not a parse tree according to the
meaning of the act; it is a tree-like API which provides access to
an underlying implementation that may or may not look like a parse tree.

-- 
John Cowan	http://www.ccil.org/~cowan		cowan@ccil.org
	You tollerday donsk?  N.  You tolkatiff scowegian?  Nn.
	You spigotty anglease?  Nnn.  You phonio saxo?  Nnnn.
		Clear all so!  'Tis a Jute.... (Finnegans Wake 16.5)

Received on Monday, 2 November 1998 17:15:07 UTC