use of org.w3c.dom.Text in project robovm by robovm.
the class DomTest method testCloneNode.
public void testCloneNode() throws Exception {
document = builder.parse(new InputSource(new StringReader("<menu " + "xmlns:f=\"http://food\" xmlns:a=\"http://addons\">" + "<f:item a:standard=\"strawberry\" deluxe=\"yes\">Waffles</f:item></menu>")));
name = (Element) document.getFirstChild().getFirstChild();
Element clonedName = (Element) name.cloneNode(true);
assertNull(clonedName.getParentNode());
assertNull(clonedName.getNextSibling());
assertNull(clonedName.getPreviousSibling());
assertEquals("http://food", clonedName.getNamespaceURI());
assertEquals("f:item", clonedName.getNodeName());
assertEquals("item", clonedName.getLocalName());
assertEquals("http://food", clonedName.getNamespaceURI());
assertEquals("yes", clonedName.getAttribute("deluxe"));
assertEquals("strawberry", clonedName.getAttribute("a:standard"));
assertEquals("strawberry", clonedName.getAttributeNS("http://addons", "standard"));
assertEquals(1, name.getChildNodes().getLength());
Text clonedChild = (Text) clonedName.getFirstChild();
assertSame(clonedName, clonedChild.getParentNode());
assertNull(clonedChild.getNextSibling());
assertNull(clonedChild.getPreviousSibling());
assertEquals("Waffles", clonedChild.getTextContent());
}
use of org.w3c.dom.Text in project robovm by robovm.
the class DomTest method testCoalescingOn.
public void testCoalescingOn() throws Exception {
String xml = "<foo>abc<![CDATA[def]]>ghi</foo>";
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setCoalescing(true);
document = factory.newDocumentBuilder().parse(new InputSource(new StringReader(xml)));
Element documentElement = document.getDocumentElement();
Text text = (Text) documentElement.getFirstChild();
assertEquals("abcdefghi", text.getTextContent());
assertNull(text.getNextSibling());
}
use of org.w3c.dom.Text in project robovm by robovm.
the class DomTest method testExpandingEntityReferencesOn.
public void testExpandingEntityReferencesOn() throws Exception {
String xml = "<!DOCTYPE foo [ <!ENTITY def \"DEF\"> ]>" + "<foo>abc&def;ghi</foo>";
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setExpandEntityReferences(true);
document = factory.newDocumentBuilder().parse(new InputSource(new StringReader(xml)));
Element documentElement = document.getDocumentElement();
Text text = (Text) documentElement.getFirstChild();
assertEquals("This implementation doesn't expand entity references", "abcDEFghi", text.getTextContent());
assertNull(text.getNextSibling());
}
use of org.w3c.dom.Text in project robovm by robovm.
the class DomTest method testCoalescingOff.
public void testCoalescingOff() throws Exception {
String xml = "<foo>abc<![CDATA[def]]>ghi</foo>";
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setCoalescing(false);
document = factory.newDocumentBuilder().parse(new InputSource(new StringReader(xml)));
Element documentElement = document.getDocumentElement();
Text abc = (Text) documentElement.getFirstChild();
assertEquals("abc", abc.getTextContent());
CDATASection def = (CDATASection) abc.getNextSibling();
assertEquals("def", def.getTextContent());
Text ghi = (Text) def.getNextSibling();
assertEquals("ghi", ghi.getTextContent());
assertNull(ghi.getNextSibling());
}
use of org.w3c.dom.Text in project robovm by robovm.
the class DomTest method testReplaceWholeTextOnly.
public void testReplaceWholeTextOnly() throws TransformerException {
String original = domToString(document);
Text replacement = vitamincText.replaceWholeText("70%");
assertEquals(Node.TEXT_NODE, replacement.getNodeType());
assertSame(vitamincText, replacement);
String expected = original.replace("60%", "70%");
assertEquals(expected, domToString(document));
}
Aggregations