@Test public void canBuildXml_withNamespaces() { Document doc = XmlUtils.buildXml("test", "ns1", "http://inftec.ch/ns1") .addNamespace("ns2", "http://inftec.ch/ns2") .addChild("child") .endChild() .addChild("child", "ns2") .addChild("child", "ns1") .endChild() .endChild() .getDocument(); TestUtils.assertEqualsXmlResource("XmlUtilsTest_canBuildXml_withNamespaces.xml", doc); }
/** * Tests the toString method of XmlUtil. */ @Test public void xmlTtoString() { // Create XML document Document doc = XmlUtils.buildXml("root") .addChild("child1") .setAttribute("childAttr1", "val1") .setAttribute("childAttr2", "val2") .addText("Text1") .endChild() .addChild("child2") .addChild("subChild1") .addText("Text2") .endChild() .endChild() .getDocument(); // Test simple XML, without declaration and indentation String simpleXml = XmlUtils.toString(doc, false, false); TestUtils.assertEqualsResource("xmlToString_simpleXml.xml", simpleXml); // Test complete XML, with declaration and indentation String fullXml = XmlUtils.toString(doc, true, true); TestUtils.assertEqualsResource("xmlToString_fullXml.xml", fullXml); }
@Test public void canCompare_xmlDocument_toResource() { Document doc = XmlUtils.buildXml("root").addChild("child").endChild().getDocument(); TestUtils.assertEqualsXmlResource("TestUtilsTest_canCompare_xmlDocument_toResource.xml", doc); }