-
- private static Document loadDocument(final String xmlPath) throws IOException, SAXException {
- final InputStream resourceAsStream = Bug5446Test.class.getResourceAsStream(xmlPath);
- return requireNonNull(readXmlToDocument(resourceAsStream));
- }
-
- private static Document readXmlToDocument(final InputStream xmlContent) throws IOException, SAXException {
- final Document doc = UntrustedXML.newDocumentBuilder().parse(xmlContent);
- doc.getDocumentElement().normalize();
- return doc;
- }
-
- private static String toString(final Node xml) {
- try {
- final Transformer transformer = TransformerFactory.newInstance().newTransformer();
- transformer.setOutputProperty(OutputKeys.INDENT, "yes");
- transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
-
- final StreamResult result = new StreamResult(new StringWriter());
- final DOMSource source = new DOMSource(xml);
- transformer.transform(source, result);
-
- return result.getWriter().toString();
- } catch (IllegalArgumentException | TransformerFactoryConfigurationError | TransformerException e) {
- throw new RuntimeException("Unable to serialize xml element " + xml, e);
- }
- }