Including CDATA wrapper while Marshalling
I am generating xml using XMLBeans . Is there a way to include CDATA Wrapper automatically for required elements in the output xml document . For example , my output xml should look like this :
<employee>
<name><![CDATA[NAME]]></name>
<address><![CDATA[ADDRESS]]></address>
</employee>
1) Can we write XSD in such a way , that whenever i set value for <name>
element in my program using XMLBean开发者_StackOverflow中文版s , the output xml should contain name element like this : <name><![CDATA[NAME]]></name>
instead of <name>NAME</name>
2) Is there a way in XMLBeans to produce CDATA Wrapper for specific elements .
Any Help would be appreciated.
See this thread. In short:
node.setFoo("ABCDE12345");
XmlCursor c = node.xgetFoo().newCursor();
c.toFirstContentToken();
c.setBookmark(CDataBookmark.CDATA_BOOKMARK);
And then when you go to "save" the document be sure to pass in an XmlOptions like:
XmlOptions opts = new XmlOptions().setUseCDataBookmarks();
node.xmlText(opts);
Just reading docs - I'm not an XMLBeans user. If someone with experience writes differently - trust them, not me.
See CDataBookmark and XmlOptions.setCDATAEntityCountThreshold,setUseCDataBookmarks,setSaveCDataLengthThreshold.
The docs on how you set a CDataBookmark in the text aren't clear. See this bit from Nabble.
精彩评论