use of org.w3c.dom.DocumentFragment in project webservices-axiom by apache.
the class TestLookupNamespaceURI method runTest.
protected void runTest() throws Throwable {
Document document = dbf.newDocumentBuilder().newDocument();
DocumentFragment fragment = document.createDocumentFragment();
Element element = document.createElementNS("urn:test", "ns:root");
element.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:ns", "urn:test");
fragment.appendChild(element);
assertNull(fragment.lookupNamespaceURI("ns"));
}
use of org.w3c.dom.DocumentFragment in project webservices-axiom by apache.
the class TestInsertBeforeWithDocumentFragment 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, "parent1");
Element a = document.createElementNS(null, "a");
Element b = document.createElementNS(null, "b");
element.appendChild(a);
element.appendChild(b);
element.insertBefore(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(b, children.item(3));
assertSame(element, x.getParentNode());
assertSame(element, y.getParentNode());
assertNull(fragment.getFirstChild());
assertNull(fragment.getLastChild());
assertEquals(0, fragment.getChildNodes().getLength());
}
use of org.w3c.dom.DocumentFragment in project webservices-axiom by apache.
the class TestReplaceChildLastWithDocumentFragment 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, b);
NodeList children = element.getChildNodes();
assertEquals(3, children.getLength());
assertSame(a, children.item(0));
assertSame(x, children.item(1));
assertSame(y, children.item(2));
assertSame(element, x.getParentNode());
assertSame(element, y.getParentNode());
assertNull(fragment.getFirstChild());
assertNull(fragment.getLastChild());
assertEquals(0, fragment.getChildNodes().getLength());
assertSame(a, element.getFirstChild());
assertSame(y, element.getLastChild());
}
use of org.w3c.dom.DocumentFragment in project j2objc by google.
the class InnerNodeImpl method insertChildAt.
/**
* Inserts {@code newChild} at {@code index}. If it is already child of
* another node, it is removed from there.
*/
Node insertChildAt(Node newChild, int index) throws DOMException {
if (newChild instanceof DocumentFragment) {
NodeList toAdd = newChild.getChildNodes();
for (int i = 0; i < toAdd.getLength(); i++) {
insertChildAt(toAdd.item(i), index + i);
}
return newChild;
}
LeafNodeImpl toInsert = (LeafNodeImpl) newChild;
if (toInsert.document != null && document != null && toInsert.document != document) {
throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, null);
}
if (toInsert.isParentOf(this)) {
throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, null);
}
if (toInsert.parent != null) {
int oldIndex = toInsert.index;
toInsert.parent.children.remove(oldIndex);
toInsert.parent.refreshIndices(oldIndex);
}
children.add(index, toInsert);
toInsert.parent = this;
refreshIndices(index);
return newChild;
}
use of org.w3c.dom.DocumentFragment in project j2objc by google.
the class XObject method rtree.
/**
* Cast result object to a result tree fragment.
*
* @param support XPath context to use for the conversion
*
* @return the objec as a result tree fragment.
*/
public DocumentFragment rtree(XPathContext support) {
DocumentFragment docFrag = null;
int result = rtf();
if (DTM.NULL == result) {
DTM frag = support.createDocumentFragment();
// %OPT%
frag.appendTextChild(str());
docFrag = (DocumentFragment) frag.getNode(frag.getDocument());
} else {
DTM frag = support.getDTM(result);
docFrag = (DocumentFragment) frag.getNode(frag.getDocument());
}
return docFrag;
}
Aggregations