Title: Concerning CData and pretty print

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

Reply via email to