Re: Some Issues while testing
Martin Klang <[email protected]> Thu, 17 Jul 2003 22:58:08 +0000 (GMT)
| Newsgroups | gmane.text.xml.o-xml |
|---|---|
| Message-ID | <[email protected]> |
On Thu, 17 Jul 2003, Glen Barnes wrote: > 3. append Node manipluation palces node in wrong place? > > In the example I attached the following line <o:do > select="$blog/blog/entries/entry.append($newEntry)"/> appends the new > entry BETWEEN the first and third 'entry' nodes. Is this correct? I > thought it would add it after the LAST 'entry' node. The node actually gets appended to the first "entry" element, which means it isn't between the first and third but below the first. That's why you've got the two closing "entry" tags: > 4. Extra </entry> entry To add the node to the end of the child nodes of "entries" you need to do: <o:do select="$blog/blog/entries.append($newEntry)"/> however, your question is still interesting for the following reason -> The result of an XPath location path, such as "$blog/blog/entries/entry", is a nodeset. In this example it contains all "entry" nodes in the document. The function Nodeset.append(Node other) adds a node to the child nodes of the first node in the nodeset it is invoked on. Wot?? Well it does. A lot of the time it works fine, but often the result is counter intuitive or plain wrong. I think the append() function, when invoked on a nodeset, should maybe append to every node in the set. But then you can't really dynamically add a node to a nodeset, eg a variable, only to the nodes it contains! The problem really is that the Nodeset type is used both for general container objects, and to store intermediate results such XPath result sets. In the latter case it is not really the nodeset we're interested in but the contents. In the former case we want to be able to manipulate the nodeset itself directly (get size, add/remove nodes), and not invoke methods on its contents. Here's what i'd like to suggest: - remove append() from the Nodeset type. - create Nodeset.add() function that doesn't clash with Element.append(). - add function String.append() for mixed content (and string concatenation). - add more useful Nodeset functions: size(), reverse(), sort() - any others? These changes would mean that Glen's expression: "$blog/blog/entries/entry.append($newEntry)" would call append() on every "entry" element, whereas "$blog.add($newEntry)" would add it to the variable nodeset correctly, and "$blog/blog/entries.append($newEntry)" would work as intended. But "$blog/blog/entries.add($newEntry)" would not have any real effect, because the XPath result nodeset would, once updated, be discarded. This issue really has to be addressed properly in the 1.0 version of the spec. I'm hoping that the current ObjectBox release will provide enough of a basis to work all these sorts of problems out before we go into production/stable spec and implementation releases. cheers, and thanks Glen for the much needed feedback, /m Martin Klang http://www.o-xml.org - the object-oriented XML programming language