Search in sources :

Example 21 with DocumentFragment

use of org.w3c.dom.DocumentFragment in project robovm by robovm.

the class ImportNode method testImportNode4.

public void testImportNode4() throws Throwable {
    Document doc;
    Document aNewDoc;
    DocumentFragment docFrag;
    Comment comment;
    Node aNode;
    NodeList children;
    Node child;
    String childValue;
    doc = (Document) load("staff", builder);
    aNewDoc = (Document) load("staff", builder);
    docFrag = aNewDoc.createDocumentFragment();
    comment = aNewDoc.createComment("descendant1");
    aNode = docFrag.appendChild(comment);
    aNode = doc.importNode(docFrag, true);
    children = aNode.getChildNodes();
    assertEquals("throw_Size", 1, children.getLength());
    child = aNode.getFirstChild();
    childValue = child.getNodeValue();
    assertEquals("descendant1", "descendant1", childValue);
}
Also used : Comment(org.w3c.dom.Comment) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document) DocumentFragment(org.w3c.dom.DocumentFragment)

Example 22 with DocumentFragment

use of org.w3c.dom.DocumentFragment in project robovm by robovm.

the class DocumentImportNode method testImportNode10.

public void testImportNode10() throws Throwable {
    Document doc;
    DocumentFragment docFragment;
    NodeList childList;
    boolean success;
    Node addressNode;
    Node importedDocFrag;
    doc = (Document) load("staffNS", builder);
    docFragment = doc.createDocumentFragment();
    childList = doc.getElementsByTagNameNS("*", "address");
    addressNode = childList.item(0);
    docFragment.appendChild(addressNode);
    importedDocFrag = doc.importNode(docFragment, true);
    success = importedDocFrag.hasChildNodes();
    assertTrue("documentimportnode10", success);
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) DocumentFragment(org.w3c.dom.DocumentFragment)

Example 23 with DocumentFragment

use of org.w3c.dom.DocumentFragment in project robovm by robovm.

the class DocumentImportNode method testImportNode9.

public void testImportNode9() throws Throwable {
    Document doc;
    DocumentFragment docFragment;
    NodeList childList;
    boolean success;
    Node addressNode;
    Node importedDocFrag;
    doc = (Document) load("staffNS", builder);
    docFragment = doc.createDocumentFragment();
    childList = doc.getElementsByTagNameNS("*", "address");
    addressNode = childList.item(0);
    docFragment.appendChild(addressNode);
    importedDocFrag = doc.importNode(docFragment, false);
    success = importedDocFrag.hasChildNodes();
    assertFalse("documentimportnode09", success);
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) DocumentFragment(org.w3c.dom.DocumentFragment)

Example 24 with DocumentFragment

use of org.w3c.dom.DocumentFragment in project robovm by robovm.

the class HCNodeDocumentFragmentNormalize method testNodeDocumentFragmentNormalize2.

public void testNodeDocumentFragmentNormalize2() throws Throwable {
    Document doc;
    DocumentFragment docFragment;
    Text txtNode;
    doc = (Document) load("hc_staff", builder);
    docFragment = doc.createDocumentFragment();
    txtNode = doc.createTextNode("");
    docFragment.appendChild(txtNode);
    docFragment.normalize();
    txtNode = (Text) docFragment.getFirstChild();
    assertNull("noChild", txtNode);
}
Also used : Text(org.w3c.dom.Text) Document(org.w3c.dom.Document) DocumentFragment(org.w3c.dom.DocumentFragment)

Example 25 with DocumentFragment

use of org.w3c.dom.DocumentFragment in project robovm by robovm.

the class HCNodeDocumentFragmentNormalize method testNodeDocumentFragmentNormalize1.

/**
     * Runs the test case.
     *
     * @throws Throwable
     *             Any uncaught exception causes test to fail
     */
public void testNodeDocumentFragmentNormalize1() throws Throwable {
    Document doc;
    DocumentFragment docFragment;
    String nodeValue;
    Text txtNode;
    Node retval;
    doc = (Document) load("hc_staff", builder);
    docFragment = doc.createDocumentFragment();
    txtNode = doc.createTextNode("foo");
    retval = docFragment.appendChild(txtNode);
    txtNode = doc.createTextNode("bar");
    retval = docFragment.appendChild(txtNode);
    docFragment.normalize();
    txtNode = (Text) docFragment.getFirstChild();
    nodeValue = txtNode.getNodeValue();
    assertEquals("normalizedNodeValue", "foobar", nodeValue);
    retval = txtNode.getNextSibling();
    assertNull("singleChild", retval);
}
Also used : Node(org.w3c.dom.Node) Text(org.w3c.dom.Text) Document(org.w3c.dom.Document) 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