Search in sources :

Example 61 with Text

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

the class TestAppendChild method runTest.

protected void runTest() throws Throwable {
    String elementName = "TestElem";
    String childElemName = "TestChildElem";
    String childTextValue = "text value of the child text node";
    //Apending am Element node
    Document doc = dbf.newDocumentBuilder().newDocument();
    Element elem = doc.createElement(elementName);
    Element childElem = doc.createElement(childElemName);
    elem.appendChild(childElem);
    Element addedChild = (Element) elem.getFirstChild();
    assertNotNull("Child Element node missing", addedChild);
    assertEquals("Incorre node object", childElem, addedChild);
    elem = doc.createElement(elementName);
    Text text = doc.createTextNode(childTextValue);
    elem.appendChild(text);
    Text addedTextnode = (Text) elem.getFirstChild();
    assertNotNull("Child Text node missing", addedTextnode);
    assertEquals("Incorrect node object", text, addedTextnode);
}
Also used : Element(org.w3c.dom.Element) Text(org.w3c.dom.Text) Document(org.w3c.dom.Document)

Example 62 with Text

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

the class TestAppendChildWrongDocument method runTest.

protected void runTest() throws Throwable {
    DocumentBuilder documentBuilder = dbf.newDocumentBuilder();
    Document document1 = documentBuilder.newDocument();
    Document document2 = documentBuilder.newDocument();
    Element element = document1.createElementNS(null, "element");
    Text text = document2.createTextNode("test");
    try {
        element.appendChild(text);
        fail("Expected DOMException");
    } catch (DOMException ex) {
        assertEquals(DOMException.WRONG_DOCUMENT_ERR, ex.code);
    }
}
Also used : DOMException(org.w3c.dom.DOMException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) Text(org.w3c.dom.Text) Document(org.w3c.dom.Document)

Example 63 with Text

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

the class TestCreateText method runTest.

protected void runTest() throws Throwable {
    String textValue = "temp text value";
    Document doc = dbf.newDocumentBuilder().newDocument();
    Text txt = doc.createTextNode(textValue);
    assertEquals("Text value mismatch", textValue, txt.getData());
}
Also used : Text(org.w3c.dom.Text) Document(org.w3c.dom.Document)

Example 64 with Text

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

the class TestInsertSiblingAfterFromForeignDocument method runTest.

@Override
protected void runTest() throws Throwable {
    DocumentBuilder db = ((DOMMetaFactory) metaFactory).newDocumentBuilderFactory().newDocumentBuilder();
    Document document1 = db.newDocument();
    Element element1 = document1.createElementNS(null, "element1");
    Text text = document1.createTextNode("test");
    element1.appendChild(text);
    Document document2 = db.newDocument();
    Element element2 = document2.createElementNS(null, "element2");
    ((OMNode) text).insertSiblingAfter((OMElement) element2);
    // Assert that the new child is not a copy, but the original element
    assertSame(element2, element1.getLastChild());
    // Assert that the owner document of element2 was changed
    assertSame(document1, element2.getOwnerDocument());
}
Also used : OMNode(org.apache.axiom.om.OMNode) DocumentBuilder(javax.xml.parsers.DocumentBuilder) OMElement(org.apache.axiom.om.OMElement) Element(org.w3c.dom.Element) Text(org.w3c.dom.Text) Document(org.w3c.dom.Document)

Example 65 with Text

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

the class TestInsertSiblingBeforeFromForeignDocument method runTest.

@Override
protected void runTest() throws Throwable {
    DocumentBuilder db = ((DOMMetaFactory) metaFactory).newDocumentBuilderFactory().newDocumentBuilder();
    Document document1 = db.newDocument();
    Element element1 = document1.createElementNS(null, "element1");
    Text text = document1.createTextNode("test");
    element1.appendChild(text);
    Document document2 = db.newDocument();
    Element element2 = document2.createElementNS(null, "element2");
    ((OMNode) text).insertSiblingBefore((OMElement) element2);
    // Assert that the new child is not a copy, but the original element
    assertSame(element2, element1.getFirstChild());
    // Assert that the owner document of element2 was changed
    assertSame(document1, element2.getOwnerDocument());
}
Also used : OMNode(org.apache.axiom.om.OMNode) DocumentBuilder(javax.xml.parsers.DocumentBuilder) OMElement(org.apache.axiom.om.OMElement) 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