Search in sources :

Example 71 with Text

use of org.w3c.dom.Text in project webservices-axiom by apache.

the class TestLookupNamespaceURIWithoutParent method runTest.

protected void runTest() throws Throwable {
    Document document = dbf.newDocumentBuilder().newDocument();
    Text text = document.createTextNode("test");
    assertNull(text.lookupNamespaceURI("ns"));
}
Also used : Text(org.w3c.dom.Text) Document(org.w3c.dom.Document)

Example 72 with Text

use of org.w3c.dom.Text in project webservices-axiom by apache.

the class TestReplaceDataAppend method runTest.

protected void runTest() throws Throwable {
    Document doc = dbf.newDocumentBuilder().newDocument();
    Text text = doc.createTextNode("AB");
    text.replaceData(2, 0, "CD");
    assertThat(text.getData()).isEqualTo("ABCD");
}
Also used : Text(org.w3c.dom.Text) Document(org.w3c.dom.Document)

Example 73 with Text

use of org.w3c.dom.Text in project webservices-axiom by apache.

the class TestSplitTextWithoutParent method runTest.

@Override
protected void runTest() throws Throwable {
    Document document = dbf.newDocumentBuilder().newDocument();
    Text text = document.createTextNode("ABCD");
    Text newText = text.splitText(2);
    assertThat(text.getData()).isEqualTo("AB");
    assertThat(newText.getData()).isEqualTo("CD");
    assertThat(newText.getOwnerDocument()).isSameAs(document);
}
Also used : Text(org.w3c.dom.Text) Document(org.w3c.dom.Document)

Example 74 with Text

use of org.w3c.dom.Text in project webservices-axiom by apache.

the class TestSplitText method runTest.

protected void runTest() throws Throwable {
    String textValue = "temp text value";
    Document doc = dbf.newDocumentBuilder().newDocument();
    Element element = doc.createElement("test");
    Text txt = doc.createTextNode(textValue);
    element.appendChild(txt);
    txt.splitText(3);
    assertNotNull("Text value missing in the original Text node", txt.getNodeValue());
    assertNotNull("Sibling missing after split", txt.getNextSibling());
    assertNotNull("Text value missing in the new split Text node", txt.getNextSibling().getNodeValue());
    assertEquals("Incorrect split point", textValue.substring(0, 3), txt.getNodeValue());
    assertEquals("Incorrect split point", textValue.substring(3, textValue.length()), txt.getNextSibling().getNodeValue());
}
Also used : Element(org.w3c.dom.Element) Text(org.w3c.dom.Text) Document(org.w3c.dom.Document)

Example 75 with Text

use of org.w3c.dom.Text in project webservices-axiom by apache.

the class TestReplaceChildNotFound method runTest.

protected void runTest() throws Throwable {
    Document document = dbf.newDocumentBuilder().newDocument();
    Element root = document.createElementNS(null, "root");
    root.appendChild(document.createElementNS(null, "child"));
    Text node1 = document.createTextNode("test1");
    Text node2 = document.createTextNode("test2");
    try {
        root.replaceChild(node2, node1);
        fail("Expected DOMException");
    } catch (DOMException ex) {
        assertEquals(DOMException.NOT_FOUND_ERR, ex.code);
    }
}
Also used : DOMException(org.w3c.dom.DOMException) Element(org.w3c.dom.Element) Text(org.w3c.dom.Text) Document(org.w3c.dom.Document)

Aggregations

Text (org.w3c.dom.Text)166 Element (org.w3c.dom.Element)93 Document (org.w3c.dom.Document)64 Node (org.w3c.dom.Node)58 NodeList (org.w3c.dom.NodeList)35 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)23 DocumentBuilder (javax.xml.parsers.DocumentBuilder)22 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)17 IOException (java.io.IOException)14 Attr (org.w3c.dom.Attr)14 InputSource (org.xml.sax.InputSource)11 StringReader (java.io.StringReader)10 SAXException (org.xml.sax.SAXException)8 ArrayList (java.util.ArrayList)7 DOMException (org.w3c.dom.DOMException)7 Test (org.junit.Test)6 DOMSource (javax.xml.transform.dom.DOMSource)5 NamedNodeMap (org.w3c.dom.NamedNodeMap)5 HashMap (java.util.HashMap)4 DocumentFragment (org.w3c.dom.DocumentFragment)4