@Override public byte[] convert(Document original) { return original.asXML().getBytes(IOUtils.UTF8); } }
protected ConfigSaveState updatePartial(String xmlPartial, final String md5) throws Exception { LOGGER.debug("[Config Save] Updating partial"); Document document = documentRoot(); Element root = document.getRootElement(); Element configElement = ((Element) root.selectSingleNode(getXpath())); List nodes = configElement.getParent().content(); int index = nodes.indexOf(configElement); LOGGER.debug("[Config Save] Converting to object"); Element newConfigElement = reader.read(new StringReader(xmlPartial)).getRootElement(); nodes.set(index, newConfigElement); return saveConfig(document.asXML(), md5); }
log.debug("Like this: {}", doc.asXML()); return VerifyResult.error;
try { saxReader.read( new StringReader( doc.asXML() ) );
final Document dom = DocumentHelper.createDocument().addElement("some-name") .addAttribute("attr1", "val1") .addAttribute("attr2", "val2") .addElement("some-other-name").getDocument(); System.out.println(dom.asXML());
public static String readFile(String xmlFileName) throws IOException, DocumentException { try (final InputStream is = new ClassPathResource(xmlFileName).getInputStream()) { final SAXReader reader = new SAXReader(); final Document doc = reader.read(inputStream); return doc.asXML(); } }
String xml = ... SAXReader reader = new SAXReader(); Document document = reader.read(new ByteArrayInputStream(xml.getBytes())); document.accept(new NameSpaceCleaner()); return document.asXML();
private org.w3c.dom.Document convertToDOM(org.dom4j.Document doc) { String xml = doc.asXML(); try { return StaxUtils.read(new StringReader(xml)); } catch (Exception ex) { throw ExceptionUtils.toInternalServerErrorException(ex, null); } }
private org.w3c.dom.Document convertToDOM(org.dom4j.Document doc) { String xml = doc.asXML(); try { return StaxUtils.read(new StringReader(xml)); } catch (Exception ex) { throw ExceptionUtils.toInternalServerErrorException(ex, null); } } }
/** * Converts a DOM to an XML string. * @param dom the dome object to convert * @return A string representation of the document */ public static String toXml(Document dom) { return new DOMReader().read(dom).asXML(); }
protected Document domRoundTrip(Document document) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); org.w3c.dom.Document domDocument = builder.parse(new InputSource( new StringReader(document.asXML()))); // now lets read it back as a DOM4J object DOMReader domReader = new DOMReader(); return domReader.read(domDocument); }
public void testEscapedComment() throws Exception { String txt = "<eg><!-- <head> & <body> --></eg>"; Document doc = DocumentHelper.parseText(txt); Element eg = doc.getRootElement(); System.out.println(doc.asXML()); assertEquals("<!-- <head> & <body> -->", eg.getText()); } }
public void testBug799656() throws Exception { Document document = DocumentFactory.getInstance().createDocument(); Element el = document.addElement("root"); el.setText("text with an \u00FC in it"); // u00FC is umlaut System.out.println(document.asXML()); DocumentHelper.parseText(document.asXML()); }
public void testNormalize() throws Exception { String text = document.asXML(); document.normalize(); String normalizedText = document.asXML(); log("Initial: " + text); log("Normalized: " + normalizedText); String value = document.valueOf("/dummy/full"); assertEquals("Should not trim text", " node ", value); }
public void testNoAdjacentText() throws Exception { // After reading using SAXReader with mergeAdjacentText true, // no two Text objects should be adjacent to each other in the // document. SAXReader reader = new SAXReader(); reader.setMergeAdjacentText(true); Document document = getDocument(INPUT_XML_FILE, reader); checkNoAdjacent(document.getRootElement()); log("No adjacent Text nodes in " + document.asXML()); }
public void testNullCData() { Element e = DocumentHelper.createElement("test"); e.add(DocumentHelper.createElement("another").addCDATA(null)); Document doc = DocumentHelper.createDocument(e); assertEquals(-1, e.asXML().indexOf("null")); assertEquals(-1, doc.asXML().indexOf("null")); System.out.println(e.asXML()); System.out.println(doc.asXML()); }
public void testAsXMLWithEncoding() throws Exception { DefaultDocument document = new DefaultDocument(); document.addElement("root"); document.setXMLEncoding("ISO-8859-1"); Document doc = DocumentHelper.parseText("<?xml version='1.0' " + "encoding='ISO-8859-1'?><root/>"); String xml1 = document.asXML(); String xml2 = doc.asXML(); assertTrue(xml1.indexOf("ISO-8859-1") != -1); assertTrue(xml2.indexOf("ISO-8859-1") != -1); }
public void testDom4jAddNodeCreateCopy() { Document maindoc = DocumentHelper.createDocument(); Element docroot = maindoc.addElement("document"); Element header = docroot.addElement("header").addText("Some Text"); Document subdoc = DocumentHelper.createDocument(); Element docroot2 = subdoc.addElement("document"); docroot2.add(((Element) maindoc.selectSingleNode("/document/header")) .createCopy()); assertEquals(subdoc.asXML(), maindoc.asXML()); }
public void testDom4jAddNodeClone() { Document maindoc = DocumentHelper.createDocument(); Element docroot = maindoc.addElement("document"); Element header = docroot.addElement("header").addText("Some Text"); Document subdoc = DocumentHelper.createDocument(); Element docroot2 = subdoc.addElement("document"); docroot2.add((Element) maindoc.selectSingleNode("/document/header") .clone()); assertEquals(subdoc.asXML(), maindoc.asXML()); }