Hi Jorg,
I created a simple test as you recommended, and the results were as I
expected. The CDATA contents were not read. Here is the test:
@Test
Public void testReadCdata(){
Xstream xstream = new Xstream(new StaxDriver());
String contents = "<tag>my data conents</tag>";
String xml = "<string><![CDATA[" + contents + "]]></string>";
String results = (String) xstream.fromXML(xml);
assertEquals(contents, results);
}
"results" is always empty.
I'm using Oracle Java 1.6_033.
I also wrote a test to write "CDATA" and it is always encoding "<" & ">"
characters like "lt&;", etc.
What am I doing wrong?
Keith
On 2/26/13 5:46 PM, "Jörg Schaible" <[email protected]> wrote:
>Hi Keith,
>
>Wire, Keith C wrote:
>
>> Hi All,
>>
>> I'm using the StaxDriver to gain support of namespaces in Xstream.
>
>Do you have an idea, which StaX implementation is selected? The
>StaXDriver
>itself will only use the default implementation of your environment and
>that
>might change with the Java libraries on your classpath.
>
>> Really, I care that it ignores them when unmarshalling xml. Anyhow,
>>when
>> unmarshalling XML using the StaxDriver / StaxReader I discovered it
>> ignored CDATA tags.
>
>This is strange in so far as XStream contains unit tests with CDATA and
>there all directly supported StAX implementations (BEA RI, Woodstox, Java
>6
>Runtime) run these tests successfully.
>
>> Upon investigation I tracked down the issue to the
>> following method on the StaxReader:
>>
>> protected int pullNextEvent() {
>> try {
>> switch(in.next()) {
>> case XMLStreamConstants.START_DOCUMENT:
>> case XMLStreamConstants.START_ELEMENT:
>> return START_NODE;
>> case XMLStreamConstants.END_DOCUMENT:
>> case XMLStreamConstants.END_ELEMENT:
>> return END_NODE;
>> case XMLStreamConstants.CHARACTERS:
>> return TEXT;
>> case XMLStreamConstants.COMMENT:
>> return COMMENT;
>> default:
>> return OTHER;
>> }
>> } catch (XMLStreamException e) {
>> throw new StreamException(e);
>> }
>> }
>>
>> The easy fix is to add "case XMLStreamConstants.CDATA" to also return
>> "TEXT". Due to the constructor of the StaxReader calling moveDown() I
>>am
>> unable to Override the "pullNextEvent()" method to solve this on my own.
>
>There's no need. See Javadoc to javax.xml.stream.events.Characters. It
>handles also CDATA.
>
>> I attempted to create a JIRA ticket for this issue but was unable to
>> request an account.
>
>Alas, you're right, the description to create an account no longer works
>:-/
>You'll have to create now an account at xircles.codehaus.org.
>
>> Please let me know if there is an alternative Driver to use that will
>> allow me to ignore/drop namespaces while unmarshalling that also
>>supports
>> unmarshalling and marshaling CDATA.
>
>Maybe you can create a little unit test that describes your behavior. A
>short xstream.fromXML("<string><![CDATA[ ... ]]>") should be enough to
>reveal a problem.
>
>Regards,
>Jörg
>
>
>---------------------------------------------------------------------
>To unsubscribe from this list, please visit:
>
> http://xircles.codehaus.org/manage_email
>
>
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email