beckchr / staxon

JSON via StAX
107 stars 47 forks source link

Converting XML to JSON with empty CDATA #15

Closed maheshh14 closed 11 years ago

maheshh14 commented 11 years ago

While we try processing an XML to convert to JSON, the process crashes with an IndexOutOfBoundsException exception.

Example XML data: `<?xml version="1.0" encoding="UTF-8"?>

`
beckchr commented 11 years ago

This happens to be a problem during XSLT transformation, which fails to read the XML (probably a bug in Xerces/Xalan). This is not a StAXON issue:

java.lang.IndexOutOfBoundsException
at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.getTextCharacters(XMLStreamReaderImpl.java:1147)
at com.sun.org.apache.xalan.internal.xsltc.trax.StAXStream2SAX.handleCharacters(StAXStream2SAX.java:259)
at com.sun.org.apache.xalan.internal.xsltc.trax.StAXStream2SAX.bridge(StAXStream2SAX.java:169)
at com.sun.org.apache.xalan.internal.xsltc.trax.StAXStream2SAX.parse(StAXStream2SAX.java:118)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(TransformerImpl.java:678)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:727)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:340)

To get around this, you may want to use the StAX Event API instead to do the conversion. See https://github.com/beckchr/staxon/wiki/Converting-XML-to-JSON for an example.

maheshh14 commented 11 years ago

It works well now.

Thank you for the help :)