You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by Christopher Cheng <ch...@gmail.com> on 2010/06/01 11:57:14 UTC
Re: Cannot get CDATA to work
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.cheng@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);
>
>
>
RE: Cannot get CDATA to work
Posted by Cezar Andrei <ce...@oracle.com>.
Chirstofer,
Did you try the example in the javadoc?
http://xmlbeans.apache.org/docs/2.4.0/reference/org/apache/xmlbeans/XmlOptions.html#setUseCDataBookmarks()
Cezar
_____
From: Christopher Cheng [mailto:christopher.sw.cheng@gmail.com]
Sent: Tuesday, June 01, 2010 4:57 AM
To: user@xmlbeans.apache.org
Subject: Re: Cannot get CDATA to work
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 <HYPERLINK "mailto:christopher.sw.cheng@gmail.com"christopher.sw.cheng@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);