Bugs item #1374352, was opened at 2005-12-06 12:56
Message generated for change (Comment added) made by mpichler
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=116035&aid=1374352&group_id=16035
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
Summary: getUniquePath for text() may require index
Initial Comment:
An element may have multiple Text children.
Selecting them individually by xpath works, e.g.
dom.selectNodes("/a/text()[1]")
but getUniquePath on the Text node never adds
an index, e.g. returns "/a/text()" in the case above
even when there are other Text siblings (often
whitespace only), "real" text in the attached
example for better illustration).
homer<dot>pichler<at>gmx<dot>net
----------------------------------------------------------------------
Comment By: Michael Pichler (mpichler)
Date: 2006-01-31 09:10
Message:
Logged In: YES
user_id=613551
The code still contains a bug: Comment nodes are
instanceof CharacterData, but not must not be counted
as text() but instead as comment() in xpaths.
In our case we removed comment nodes before the processing,
so it does not hurt us. I did neither look into jaxen's
selectNodes implementation.
----------------------------------------------------------------------
Comment By: Michael Pichler (mpichler)
Date: 2005-12-16 14:16
Message:
Logged In: YES
user_id=613551
Hi,
here an implementation of AbstractCharacterData.getUniquePath()
that fixes the problem described (for dom4j 1.6.1):
--- cut here ---
public String getUniquePath(Element context) {
Element parent = getParent();
if ((parent != null) && (parent != context)) {
String ret = parent.getUniquePath(context) +
"/text()";
int n = parent.nodeCount ();
if (n > 1) {
// possibly multiple text() nodes
int numText = 0;
int thisText = 0;
for (int i = 0; i < n; i++) {
Node node = parent.node (i);
if (node instanceof CharacterData) {
numText++;
if (node == this) {
thisText = numText;
}
if (numText > 1 && thisText > 0)
break;
}
}
if (numText > 1) // found multiple text
children: append my index
return ret + '[' + thisText + ']';
}
return ret;
}
return "text()";
}
--- cut here ---
The frequent case of a single Text/CData child is checked
via parent.nodeCount first; only when > 1 all text children
are examined to find the right index.
Hope you find this patch useful and incorporate it into
a future release.
kind regards,
Michael Pichler
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=116035&aid=1374352&group_id=16035
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
dom4j-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dom4j-dev