[xstream-user] Re: EXTERNAL: [xstream-user] Re: StaxReader ignores CDATA

2013-02-27 Thread Wire, Keith C
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 = tagmy 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 joerg.schai...@gmx.de 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




[xstream-user] Re: StaxReader ignores CDATA

2013-02-27 Thread Jörg Schaible
Hi Keith,

Wire, Keith C wrote:

 Hi Jorg,
 
 Sorry about the XStream typo, my email likes to autocorrect.
 
 I ran the test using each of the StaxDriver Impls you suggested and here
 are the results:
 StaxDriver = Fail
 BEAStaxDriver = Success
 WstxDriver = Fail
 SjsxpDriver = Success
 
 To add to my confusion I checked out the xstream source and ran the unit
 tests for the StaxReaderTest and it passed.

Interesting. Can you tell me, which Version of Woodstox is in charge (IIRC 
CXF uses it)?

 I am using xstream 1.4.3.
 
 Also to confirm Xstream does not support writing CDATA? So I will have to
 extend say the StaxWriter to do so since the XMLStreamWriter supports it.

Well, XStream has no need to write any CDATA, it uses an own (simplified) 
writer model which utilizes an XMLStreamWriter in case of the 
StaxDriver/StaxWriter. The value of XML elements is written in the 
StaxWriter.setValue method. You may overload it to call writeCDATA instead 
of writeCharacters. For the StaxDriver simply overload the createWriter 
method to create your own derived StaxWriter.

Cheers,
Jörg



-
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email