I have the same problem and couldn't make it work. 
Basically I'm doing the same:
- Give value to the field I want as a CDATA
- Define the CDATA bookmark for that field
- Use setUseCDataBookmarks in the XmlOptions used when saving the document.

My code is basically the same:

DayType day = DayType.Factory.newInstance();
day.setDesc("<p>This is the description</p>");
XmlCursor cursor = day.xgetDesc().newCursor();
cursor.toFirstContentToken();                   
cursor.setBookmark(CDataBookmark.CDATA_BOOKMARK);
cursor.dispose();

And then in the document object to which DayType belongs:

XmlOptions opts = new XmlOptions();
opts.setUseCDataBookmarks();
out.print(document.xmlText(options));

The result is that it is not using CDATA:
...
<Day>
<Desc>&lt;p>This is the first day&lt;/p></Desc>
</Day>

What is failing?

Note that: using setSaveCDataLengthThreshold or
setSaveCDataEntityCountThreshold in the XmlOptions will work, but obviously
for every field in the document, which is not the intended behaviour.






ashirax wrote:
> 
> Hi,
> 
> I couldn't get the CDATA Bookmark to work with the code snippet
> illustrated below. Any idea what I'm doing wrong?
> 
> Thank you in advance for your help?
> 
> NodeRoot root;
> Document doc = Document.Factory.newInstance(); 
> Document.NodeRoot xmlRoot = Document.NodeRoot.Factory.newInstance()
> Node1Type n1 = xmlRoot.addNewNode1();
> Node2Type n2 = n1.addNewNode2();
> n2.setDescription("Cdata help needed"); 
> XmlCursor cursor = n2.xgetDescription().newCursor(); 
> cursor.toFirstContentToken(); 
> cursor.setBookmark(CDataBookmark.CDATA_BOOKMARK);
> cursor.dispose();
> XmlOptions opt = new XmlOptions();
> opt.setUseCDataBookmarks();
> FileOutputStream xmlFile = new FileOutputStream(filePath); 
> doc.save(xmlFile, opt); 
> xmlFile.close();
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/CDATA-Bookmark-problem%2C-xmlbeans-version-2.4-tp21448916p24840222.html
Sent from the Xml Beans - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to