Nicolas,

are you having this problem with dom4j 1.5? There was a bug in dom4j 1.4 where the XML reader created multiple CDATA sections, but this should be solved in 1.5 where only 1 CDATA node is created.

regards,
Maarten

Raggueneau Nicolas wrote:


Hello,

i have to save preformatted text inside an xml document as a CDATA node( there can be only one CDATA instance per node).

Until now i loaded this data with a node.getText().

As i am now required to pretty format the xml document, i have to do something else to load those CData nodes, because getText merges all the text (CData and text nodes), in particular the tab and newlines characters used for the pretty print.

So here is my workaround:

*private* String parseUserblock(Element in) {

       * int* iop=0;

                StringBuffer result =* new* StringBuffer();

                //Iters trough all nodes to get CData node

               * for* (Iterator i = in.nodeIterator(); i.hasNext();) {

org.dom4j.Node xmlChild = (org.dom4j.Node) i.next();

                       * if* (xmlChild* instanceof* DefaultCDATA) {

                                System.out.println(iop++);

                                result.append(xmlChild.getText());

//There should be only one CDATA, but if is it is big, it seems the loader splits

                                //the data in more CDATA node...

                                //break;

                        }

                }

                //System.out.println(result.toString());

               * return* result.toString();

        }


my problem is that it seems the xml loader splits the CDATA, so i have to append all CData nodes to get my data back.


Is it a normal behaviour?

Is my method the right way to do what i want?

thank you for reading, and for any clue you might give me.

regards,

nicolas



-------------------------------------------------------
This SF.Net email is sponsored by The 2004 JavaOne(SM) Conference
Learn from the experts at JavaOne(SM), Sun's Worldwide Java Developer
Conference, June 28 - July 1 at the Moscone Center in San Francisco, CA
REGISTER AND SAVE! http://java.sun.com/javaone/sf Priority Code NWMGYKND
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to