private final void roundTrip(boolean expand, boolean validating, String encoding, String expect) { String docloc = this.getClass().getPackage().getName().replaceAll("\\.", "/") + "/TestIssue008.xml"; URL docurl = ClassLoader.getSystemResource(docloc); if (docurl == null) { throw new IllegalStateException("Unable to get resource " + docloc); } SAXBuilder builder = new SAXBuilder(validating); // builder.setValidation(validating); builder.setExpandEntities(expand); Document doc = null; try { doc = builder.build(docurl); } catch (JDOMException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } if (doc == null) { fail("Unable to parse document, see output."); } Format fmt = Format.getCompactFormat(); if (encoding != null) { fmt.setEncoding(encoding); } XMLOutputter xout = new XMLOutputter(fmt); String actual = xout.outputString(doc.getRootElement()); assertEquals(expect, actual); }
private void checkDOM(String resname, boolean xsdvalidate) { try { org.w3c.dom.Document domdoc = HelpTestDOMBuilder.getDocument(resname, xsdvalidate); DOMBuilder db = new DOMBuilder(); Document dombuild = db.build(domdoc); Element domroot = db.build(HelpTestDOMBuilder.getRoot(domdoc)); SAXBuilder sb = new SAXBuilder(xsdvalidate ? XMLReaders.XSDVALIDATING : XMLReaders.NONVALIDATING); sb.setExpandEntities(false); Document saxbuild = sb.build(FidoFetch.getFido().getURL(resname)); Element saxroot = saxbuild.hasRootElement() ? saxbuild.getRootElement() : null; assertEquals(toString(saxbuild), toString(dombuild)); assertEquals(toString(saxroot), toString(domroot)); } catch (Exception e) { UnitTestUtil.failException("Could not parse file '" + resname + "': " + e.getMessage(), e); } }