After digging into the codes, I found out that StaxUtils is responsible to
decide whether it's 'CHARACTER' or 'CDATA'. The XMLStreamReader used is
'com.sun.xml.fastinfoset.stax.StAXDocumentParser'.
It looks like that after XMLBeans passed the XMLDocument
to StAXDocumentParser, at line 381 of StAXDocumentParser could not determine
whether it is plain CHARACTER eventType of CDATA eventType.

My quick fix is to add the followings to "copy(XMLStreamReader reader,
XMLStreamWriter writer, boolean fragment)" of StaxUtils. It's ugly, I know,
so hope somebody could fix it.

            case XMLStreamConstants.CHARACTERS:
                if (reader.getText().startsWith("<![CDATA[") &&
reader.getText().endsWith("]]>")) {
                    String text = reader.getText();
                    writer.writeCData(text.substring("<![CDATA[".length(),
text.length() - "]]>".length()));
                }
                else {
                    writer.writeCharacters(reader.getText());
                }
                break;


On Mon, May 31, 2010 at 11:40 PM, Christopher Cheng <
christopher.sw.ch...@gmail.com> wrote:

> I went thru a few posts in this list, but still no luck to get CATA to
> work. I am using xmlbeans version 2.4.
> What's wrong with the followings?
>
> node.setKey("ABCDEFG");
> XmlCursor c = node.xgetKey().newCursor();
> c.toFirstContentToken();
> c.setBookmark(CDataBookmark.CDATA_BOOKMARK);
> System.out.println(node);
>
>
>

Reply via email to