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);
}
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);
}
}
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());
}
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());
}
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());
}
Aggregations