Skip to Content.
Sympa Menu

xom-interest - [XOM-interest] Text normalization [was: XPath support in XOM]

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Wolfgang Hoschek <whoschek AT lbl.gov>
  • To: xom-interest AT lists.ibiblio.org
  • Subject: [XOM-interest] Text normalization [was: XPath support in XOM]
  • Date: Mon, 10 Jan 2005 20:57:29 -0800

Perhaps normalizeText(ParentNode) should take an extra parameter to tell whether an entire subtree should be normalized or just a part of it. That way a user could call it after all insert() and remove() calls on an given element, saving unnecessarily deep tree traversals. As in

public static void normalizeText(ParentNode node, int maxDepth)

For example normalizeText(node, 0) would just normalize the Texts that are direct children of a given node, whereas
normalizeText(node, Integer.MAX_VALUE) would recurse over the entire subtree.

Perhaps it's a gadget and not worth the extra API complexity. Perhaps it's useful. If you have an opinion either way, drop me a line.

Wolfgang.

"Michael Kay" writes:

Rather than having Saxon create virtual text nodes to represent a sequence
of adjacent XOM text nodes, I think it would be better if XOM had an option
to merge adjacent text nodes as soon as they are added to the tree.

JDOM use to do this and it was dropped because it caused confusion with the
index methods. Someone would add or remove a node and the index of the
remaining nodes wouldn't be what they expected. Examples of methods in XOM
that would have this problem are getChild(int index), insert(Node node,
int index), indexOf(), and especially getChildCount() to name a few. In
hindsight, should of keep the merge behavior and dump the methods. If you
want the 2nd child element of a parent node, and unless you take extra
measures to build a index certain nodes or find some other way to keep track
of their positions, you're going to have to search from the first child anyway.
May as well just use a iterator.

On Jan 10, 2005, at 1:59 AM, Hallvard Trætteberg wrote:

My point is that the programmer will have to understand this problem and
that this cannot be handled automatically by a XOM XPath api in a clean way
(not by auto-merging, not by including virtual nodes). The most helpful
support is Wolfgang's suggestion as shown below: a normalizeTexts method.





Archive powered by MHonArc 2.6.24.

Top of Page