Search in sources :

Example 66 with Text

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

the class TestSetTextContent method runTest.

protected void runTest() throws Throwable {
    Document doc = dbf.newDocumentBuilder().parse(new InputSource(new StringReader("<a>1<!--c--><b>2</b>3</a>")));
    Element element = doc.getDocumentElement();
    Node oldFirstChild = element.getFirstChild();
    element.setTextContent("test");
    Node firstChild = element.getFirstChild();
    assertTrue(firstChild instanceof Text);
    assertEquals("test", firstChild.getNodeValue());
    assertNull(firstChild.getNextSibling());
    assertNull(oldFirstChild.getParentNode());
    assertSame(doc, oldFirstChild.getOwnerDocument());
}
Also used : InputSource(org.xml.sax.InputSource) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) StringReader(java.io.StringReader) Text(org.w3c.dom.Text) Document(org.w3c.dom.Document)

Example 67 with Text

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

the class TestAppendData method runTest.

protected void runTest() throws Exception {
    Document document = dbf.newDocumentBuilder().newDocument();
    String localName = "TestLocalName";
    String namespace = "http://ws.apache.org/axis2/ns";
    String prefix = "axis2";
    String tempText = "The quick brown fox jumps over the lazy dog";
    String textToAppend = " followed by another fox";
    Element elem = document.createElementNS(namespace, prefix + ":" + localName);
    Text textNode = document.createTextNode(tempText);
    elem.appendChild(textNode);
    textNode.appendData(textToAppend);
    assertEquals("Text value mismatch", tempText + textToAppend, textNode.getData());
}
Also used : Element(org.w3c.dom.Element) Text(org.w3c.dom.Text) Document(org.w3c.dom.Document)

Example 68 with Text

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

the class TestGetWholeText method runTest.

protected void runTest() throws Throwable {
    Document document = dbf.newDocumentBuilder().newDocument();
    Element element = document.createElementNS(null, "test");
    element.appendChild(document.createTextNode("a"));
    element.appendChild(document.createElementNS(null, "x"));
    element.appendChild(document.createTextNode("b"));
    Text c = document.createTextNode("c");
    element.appendChild(c);
    element.appendChild(document.createTextNode("d"));
    element.appendChild(document.createProcessingInstruction("test", "test"));
    element.appendChild(document.createTextNode("e"));
    assertEquals("bcd", c.getWholeText());
}
Also used : Element(org.w3c.dom.Element) Text(org.w3c.dom.Text) Document(org.w3c.dom.Document)

Example 69 with Text

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

the class TestGetWholeTextWithComment method runTest.

protected void runTest() throws Throwable {
    Document document = dbf.newDocumentBuilder().newDocument();
    Element element = document.createElementNS(null, "test");
    Text a = document.createTextNode("a");
    element.appendChild(a);
    element.appendChild(document.createComment("comment"));
    element.appendChild(document.createTextNode("b"));
    assertEquals("a", a.getWholeText());
}
Also used : Element(org.w3c.dom.Element) Text(org.w3c.dom.Text) Document(org.w3c.dom.Document)

Example 70 with Text

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

the class TestGetWholeTextWithCDATASection method runTest.

protected void runTest() throws Throwable {
    Document document = dbf.newDocumentBuilder().newDocument();
    Element element = document.createElementNS(null, "test");
    Text a = document.createTextNode("a");
    element.appendChild(a);
    element.appendChild(document.createCDATASection("b"));
    element.appendChild(document.createTextNode("c"));
    assertEquals("abc", a.getWholeText());
}
Also used : 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