use of org.w3c.dom.DocumentFragment in project webservices-axiom by apache.
the class TestReplaceChildFirstWithDocumentFragment method runTest.
protected void runTest() throws Throwable {
Document document = dbf.newDocumentBuilder().newDocument();
DocumentFragment fragment = document.createDocumentFragment();
Element x = document.createElementNS(null, "x");
Element y = document.createElementNS(null, "y");
fragment.appendChild(x);
fragment.appendChild(y);
Element element = document.createElementNS(null, "parent");
Element a = document.createElementNS(null, "a");
Element b = document.createElementNS(null, "b");
element.appendChild(a);
element.appendChild(b);
element.replaceChild(fragment, a);
NodeList children = element.getChildNodes();
assertEquals(3, children.getLength());
assertSame(x, children.item(0));
assertSame(y, children.item(1));
assertSame(b, children.item(2));
assertSame(element, x.getParentNode());
assertSame(element, y.getParentNode());
assertNull(fragment.getFirstChild());
assertNull(fragment.getLastChild());
assertEquals(0, fragment.getChildNodes().getLength());
assertSame(x, element.getFirstChild());
assertSame(b, element.getLastChild());
}
use of org.w3c.dom.DocumentFragment in project webservices-axiom by apache.
the class TestReplaceChildMiddleWithDocumentFragment method runTest.
protected void runTest() throws Throwable {
Document document = dbf.newDocumentBuilder().newDocument();
DocumentFragment fragment = document.createDocumentFragment();
Element x = document.createElementNS(null, "x");
Element y = document.createElementNS(null, "y");
fragment.appendChild(x);
fragment.appendChild(y);
Element element = document.createElementNS(null, "parent");
Element a = document.createElementNS(null, "a");
Element b = document.createElementNS(null, "b");
Element c = document.createElementNS(null, "c");
element.appendChild(a);
element.appendChild(b);
element.appendChild(c);
element.replaceChild(fragment, b);
NodeList children = element.getChildNodes();
assertEquals(4, children.getLength());
assertSame(a, children.item(0));
assertSame(x, children.item(1));
assertSame(y, children.item(2));
assertSame(c, children.item(3));
assertSame(element, x.getParentNode());
assertSame(element, y.getParentNode());
assertNull(fragment.getFirstChild());
assertNull(fragment.getLastChild());
assertEquals(0, fragment.getChildNodes().getLength());
assertSame(a, element.getFirstChild());
assertSame(c, element.getLastChild());
}
Aggregations