use of org.w3c.dom.Text in project robovm by robovm.
the class DomTest method testReplaceWholeTextLast.
public void testReplaceWholeTextLast() throws TransformerException {
String original = domToString(document);
Text replacement = descriptionText3.replaceWholeText("Eggos");
assertSame(descriptionText3, replacement);
String expected = original.replace("Belgian<![CDATA[ waffles & strawberries (< 5g ]]>of fat)", "Eggos");
assertEquals("This implementation doesn't remove preceding nodes in replaceWholeText()", expected, domToString(document));
}
use of org.w3c.dom.Text in project robovm by robovm.
the class DomTest method testIsElementContentWhitespaceWithDeclaration.
public void testIsElementContentWhitespaceWithDeclaration() throws Exception {
String xml = "<!DOCTYPE menu [\n" + " <!ELEMENT menu (item)*>\n" + " <!ELEMENT item (#PCDATA)>\n" + "]><menu> <item/> </menu>";
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
Text text = (Text) factory.newDocumentBuilder().parse(new InputSource(new StringReader(xml))).getDocumentElement().getChildNodes().item(0);
assertTrue("This implementation does not recognize element content whitespace", text.isElementContentWhitespace());
}
use of org.w3c.dom.Text in project robovm by robovm.
the class DomTest method testExpandingEntityReferencesOff.
public void testExpandingEntityReferencesOff() throws Exception {
String xml = "<!DOCTYPE foo [ <!ENTITY def \"DEF\"> ]>" + "<foo>abc&def;ghi</foo>";
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setExpandEntityReferences(false);
document = factory.newDocumentBuilder().parse(new InputSource(new StringReader(xml)));
Element documentElement = document.getDocumentElement();
Text abc = (Text) documentElement.getFirstChild();
assertEquals("abc", abc.getTextContent());
EntityReference def = (EntityReference) abc.getNextSibling();
assertEquals("def", def.getNodeName());
Text ghi = (Text) def.getNextSibling();
assertNull(ghi.getNextSibling());
/*
* We expect the entity reference to contain one child Text node "DEF".
* The RI's entity reference contains no children. Instead it stashes
* "DEF" in the next sibling node.
*/
assertEquals("Expected text value only and no expanded entity data", "ghi", ghi.getTextContent());
NodeList defChildren = def.getChildNodes();
assertEquals("This implementation doesn't include children in entity references", 1, defChildren.getLength());
assertEquals("DEF", defChildren.item(0).getTextContent());
}
use of org.w3c.dom.Text in project spring-framework by spring-projects.
the class AbstractMarshallerTests method marshalDOMResult.
@Test
public void marshalDOMResult() throws Exception {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
Document result = builder.newDocument();
DOMResult domResult = new DOMResult(result);
marshaller.marshal(flights, domResult);
Document expected = builder.newDocument();
Element flightsElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:flights");
Attr namespace = expected.createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:tns");
namespace.setNodeValue("http://samples.springframework.org/flight");
flightsElement.setAttributeNode(namespace);
expected.appendChild(flightsElement);
Element flightElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:flight");
flightsElement.appendChild(flightElement);
Element numberElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:number");
flightElement.appendChild(numberElement);
Text text = expected.createTextNode("42");
numberElement.appendChild(text);
assertThat("Marshaller writes invalid DOMResult", result, isSimilarTo(expected));
}
use of org.w3c.dom.Text in project spring-framework by spring-projects.
the class AbstractUnmarshallerTests method unmarshalDomSource.
@Test
public void unmarshalDomSource() throws Exception {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = builder.newDocument();
Element flightsElement = document.createElementNS("http://samples.springframework.org/flight", "tns:flights");
document.appendChild(flightsElement);
Element flightElement = document.createElementNS("http://samples.springframework.org/flight", "tns:flight");
flightsElement.appendChild(flightElement);
Element numberElement = document.createElementNS("http://samples.springframework.org/flight", "tns:number");
flightElement.appendChild(numberElement);
Text text = document.createTextNode("42");
numberElement.appendChild(text);
DOMSource source = new DOMSource(document);
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
Aggregations