public void normalize() { getWrapped().normalize(); }
protected void assertDocumentsEqual(Document doc1, Document doc2) throws Exception { try { Assert.assertNotNull(doc1, "Doc1 not null"); Assert.assertNotNull(doc2, "Doc2 not null"); doc1.normalize(); doc2.normalize(); assertNodesEqual(doc1, doc2); NodeComparator comparator = new NodeComparator(); Assert.assertEquals(comparator.compare(doc1, doc2), 0, "Documents are equal"); } catch (Exception e) { log("Failed during comparison of: " + doc1 + " and: " + doc2); throw e; } }
/** * Save the contents type part. * * @param outStream * The output stream use to save the XML content of the content * types part. * @return <b>true</b> if the operation success, else <b>false</b>. */ public boolean save(OutputStream outStream) { Document xmlOutDoc = DocumentHelper.createDocument(); // Building namespace Namespace dfNs = Namespace.get("", TYPES_NAMESPACE_URI); Element typesElem = xmlOutDoc .addElement(new QName(TYPES_TAG_NAME, dfNs)); // Adding default types for (Entry<String, String> entry : defaultContentType.entrySet()) { appendDefaultType(typesElem, entry); } // Adding specific types if any exist if (overrideContentType != null) { for (Entry<PackagePartName, String> entry : overrideContentType .entrySet()) { appendSpecificTypes(typesElem, entry); } } xmlOutDoc.normalize(); // Save content in the specified output stream return this.saveImpl(xmlOutDoc, outStream); }
public void testEscapeXML() throws Exception { ByteArrayOutputStream os = new ByteArrayOutputStream(); OutputFormat format = new OutputFormat(null, false, "ISO-8859-2"); format.setSuppressDeclaration(true); XMLWriter writer = new XMLWriter(os, format); Document document = DocumentFactory.getInstance().createDocument(); Element root = document.addElement("root"); root.setText("bla &#c bla"); writer.write(document); String result = os.toString(); System.out.println(result); Document doc2 = DocumentHelper.parseText(result); doc2.normalize(); // merges adjacant Text nodes System.out.println(doc2.getRootElement().getText()); assertNodesEqual(document, doc2); }
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); }
doc.normalize(); layoutDom = this.writer.get().write(doc); person.setAttribute(Constants.PLF, layoutDom);