Search in sources :

Example 11 with DocumentFragment

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"));
}
Also used : Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) DocumentFragment(org.w3c.dom.DocumentFragment)

Example 12 with DocumentFragment

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());
}
Also used : Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document) DocumentFragment(org.w3c.dom.DocumentFragment)

Example 13 with DocumentFragment

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());
}
Also used : Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document) DocumentFragment(org.w3c.dom.DocumentFragment)

Example 14 with DocumentFragment

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;
}
Also used : DOMException(org.w3c.dom.DOMException) NodeList(org.w3c.dom.NodeList) DocumentFragment(org.w3c.dom.DocumentFragment)

Example 15 with DocumentFragment

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;
}
Also used : NodeSetDTM(org.apache.xpath.NodeSetDTM) DTM(org.apache.xml.dtm.DTM) DocumentFragment(org.w3c.dom.DocumentFragment)

Aggregations

DocumentFragment (org.w3c.dom.DocumentFragment)32 Document (org.w3c.dom.Document)20 NodeList (org.w3c.dom.NodeList)17 Node (org.w3c.dom.Node)13 Element (org.w3c.dom.Element)10 Text (org.w3c.dom.Text)4 IOException (java.io.IOException)3 LinkedHashMap (java.util.LinkedHashMap)3 DocumentBuilder (javax.xml.parsers.DocumentBuilder)3 DOMException (org.w3c.dom.DOMException)3 HashMap (java.util.HashMap)2 DTM (org.apache.xml.dtm.DTM)2 NodeSetDTM (org.apache.xpath.NodeSetDTM)2 InputSource (org.xml.sax.InputSource)2 SAXException (org.xml.sax.SAXException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 MessagingException (javax.mail.MessagingException)1