Dom4JParser implements Dom4j { public Document readLarge(Reader reader, Iterable<String> skipExactPaths) throws PatentReaderException, IOException { SAXReader sax = new SAXReader(false); ElementHandler skipElementHandler = new ElementHandler() { public void onStart(ElementPath path) { } public void onEnd(ElementPath path) { Element el = path.getCurrent(); Element parent = el.getParent(); parent.addElement(el.getName()).setText("Note: This field was truncated from the Large XML Document."); el.detach(); } }; for (String path : skipExactPaths) { sax.addHandler(path, skipElementHandler); } try { sax.setIncludeExternalDTDDeclarations(false); sax.setEncoding("UTF-8"); return sax.read(reader); } catch (DocumentException e) { reader.reset(); return fixTagsJDOM(IOUtils.toString(reader)); } }  String getSource(); Patent parse(CharSequence xmlString); Patent parse(File file); Patent parse(InputStream inputStream); Patent parse(Reader reader); Patent parse(Reader reader, Iterable<String> skipPaths); Document readLarge(Reader reader, Iterable<String> skipExactPaths); static Document fixTagsJDOM(String badXml);  }
@Test public void largeDocumentSkipElements() throws PatentReaderException, DocumentException, IOException { String xml="<xml>" + "<patent>" + "<biblio>" + "<invention-title>Widget</invention-title>" + "<inventor>John Doe</inventor>" + "</biblio>" + "<abstract>Abstract paragraph here.</abstract>" + "<description>Large content may be here.</description>" + "<claims>Large content may also be here.</claims>" + "</patent>" + "</xml>"; String[] skipPaths = new String[] {"/xml/patent/description", "/xml/patent/claims"}; class LargeParser extends Dom4JParser { @Override public Patent parse(Document document) throws PatentReaderException { return null; } } Document doc = ((Dom4JParser) new LargeParser()).readLarge(new StringReader(xml), Arrays.asList(skipPaths)); String expect = "Note: This field was truncated from the Large XML Document."; Node descN = doc.selectSingleNode("description"); assertEquals(expect, descN.getText()); Node claimsN = doc.selectSingleNode("claims"); assertEquals(expect, claimsN.getText()); }