XMLTree { public static XMLTree from(InputStream is) throws IOException { return new XMLTree(toByteArray(is)); } private  XMLTree(byte[] xml); static XMLTree from(InputStream is); static XMLTree from(java.io.File file); static XMLTree from(Path path); static XMLTree from(String xml); static XMLTree from(byte[] xml); static XMLTree create(String rootName); String getSingleText(String expression); List<String> getText(String expression); List<Element> getElements(String expression); List<R> getElements(String expression, ElementMapper<? extends R> mapper); Element getRoot(); Element getSingleElement(String expression); void updateText(String expression, String newContent); void appendChild(String expression, NewElement newElement); void insertBefore(String expression, NewElement newElement); void insertAfter(String expression, NewElement newElement); void removeElement(String expression); byte[] getBytes(); void writeTo(OutputStream outputStream); void writeTo(Path path); void writeTo(java.io.File file); @Override String toString();  }
@Test(expectedExceptions = XMLTreeException.class) public void shouldThrowExceptionWhenXMLContentContainsDoctypeDeclaration() throws Exception { String xml = "<?xml version=\"1.0\"?>\n" + "<!DOCTYPE lolz [\n" + "<!ENTITY lol \"lol\">\n" + "<!ENTITY lol2 \"&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;\">\n" + "<!ENTITY lol3 \"&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;\">\n" + "<!ENTITY lol4 \"&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;\">\n" + "<!ENTITY lol5 \"&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;\">\n" + "<!ENTITY lol6 \"&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;\">\n" + "<!ENTITY lol7 \"&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;\">\n" + "<!ENTITY lol8 \"&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;\">\n" + "<!ENTITY lol9 \"&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;\">\n" + "]>\n" + "<lolz>&lol9;</lolz>"; XMLTree.from(xml); }
@Test(dataProvider = "custom-xml-files") public void shouldBeAbleToCreateTreeFromCustomXML(File xml) throws IOException { try { XMLTree.from(xml); } catch (XMLTreeException ex) { throw new XMLTreeException(ex.getMessage() + " file: " + xml.getAbsolutePath()); } }