Search in sources :

Example 1 with CharacterDataReader

use of org.apache.axiom.ext.stax.CharacterDataReader in project webservices-axiom by apache.

the class TestCharacterDataReaderFromParser method runTest.

@Override
protected void runTest() throws Throwable {
    String text = "This is a test for the CharacterDataReader extension";
    OMDocument doc = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), new StringReader("<root>" + text + "</root>")).getDocument();
    XMLStreamReader reader = doc.getXMLStreamReader(cache);
    CharacterDataReader cdataReader = (CharacterDataReader) reader.getProperty(CharacterDataReader.PROPERTY);
    assertNotNull(cdataReader);
    assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
    StringWriter sw = new StringWriter();
    while (reader.next() == XMLStreamReader.CHARACTERS) {
        cdataReader.writeTextTo(sw);
    }
    assertEquals(text, sw.toString());
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) StringWriter(java.io.StringWriter) CharacterDataReader(org.apache.axiom.ext.stax.CharacterDataReader) StringReader(java.io.StringReader) OMDocument(org.apache.axiom.om.OMDocument)

Aggregations

StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 CharacterDataReader (org.apache.axiom.ext.stax.CharacterDataReader)1 OMDocument (org.apache.axiom.om.OMDocument)1