I'm new here, so forgive me if this has already come
up. I'm using version 1.6.1.

I've noticed that if I use node.valueOf("text()"),
sometimes, for an arbitrary node, the end of the text
will be cut off.  If I replace node.valueOf("text()")
with node.getText(), this doesn't happen.

Here is an example that produces the problem on my
machine:

import org.dom4j.DocumentHelper;
import org.dom4j.DocumentException;
import org.dom4j.Document;

public class Test {
    public static void main(String args[]) throws
DocumentException {
        Document doc =
DocumentHelper.parseText("<root><node>Some Long Long
Long Text Some Long Long Long Text Some Long Long Long
Text Some Long Long Long Text</node><node>More text
More textMore textMore textMore textMore textMore
textMore textMore text</node><node
attrib='something'>Text again.</node></root>");
       
System.out.println(doc.valueOf("/root/node[1]/text()"));
       
System.out.println(doc.valueOf("/root/node[2]/text()"));
       
System.out.println(doc.valueOf("/root/node[3]/text()"));
        System.out.println("Again:");
       
System.out.println(doc.valueOf("/root/node[1]/text()"));
       
System.out.println(doc.valueOf("/root/node[2]/text()"));
       
System.out.println(doc.valueOf("/root/node[3]/text()"));
        System.out.println("Should be:");
       
System.out.println(doc.selectSingleNode("/root/node[1]").getText());
       
System.out.println(doc.selectSingleNode("/root/node[2]").getText());
       
System.out.println(doc.selectSingleNode("/root/node[3]").getText());
    }
}

I've encountered this in a variety of places, and the
length or structure of the text doesn't seem to make a
difference.  Also, the same node is affected each
time, and if you change the text of that node, it
still cuts off at the same point.  Perhaps some nodes
get split into two text nodes?  Length doesn't seem to
be a factor, because the second node is longer than
the first.

Obviously, don't use valueOf("text()") is the
workaround, but shouldn't "text()" and getText() be
equivalent? Anyone know what is going on?



-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
dom4j-user mailing list
dom4j-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to