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: 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://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click _______________________________________________ dom4j-dev mailing list dom4j-dev@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/dom4j-dev