Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 7 8 package org.dom4j; 9 10 import junit.textui.TestRunner; 11 12 import java.util.Iterator ; 13 14 import org.dom4j.io.SAXReader; 15 16 22 public class MergeTextTest extends AbstractTestCase { 23 24 private static final String INPUT_XML_FILE = "/xml/test/mergetext.xml"; 25 26 public static void main(String [] args) { 27 TestRunner.run(MergeTextTest.class); 28 } 29 30 public void testNoAdjacentText() throws Exception { 33 SAXReader reader = new SAXReader(); 37 reader.setMergeAdjacentText(true); 38 39 Document document = getDocument(INPUT_XML_FILE, reader); 40 41 checkNoAdjacent(document.getRootElement()); 42 log("No adjacent Text nodes in " + document.asXML()); 43 } 44 45 private void checkNoAdjacent(Element parent) { 48 Node prev = null; 50 Iterator iter = parent.nodeIterator(); 51 52 while (iter.hasNext()) { 53 Node n = (Node) iter.next(); 54 55 if (n instanceof Text && ((prev != null) && prev instanceof Text)) { 56 fail("Node: " + n + " is text and so is its " 57 + "preceding sibling: " + prev); 58 } else if (n instanceof Element) { 59 checkNoAdjacent((Element) n); 60 } 61 62 prev = n; 63 } 64 } 65 } 66 67 103
| Popular Tags
|