[jdom-interest] (no subject)

Bradley S. Huffman hip at cs.okstate.edu
Fri Feb 27 07:30:36 PST 2004


"Jason Long" writes:

> I am not sure I follow.
> My code is as follows:
>  
> Element elt0 = new Element("story");
> Element elt1 = (Element) xpath.selectSingleNode(docJDOM);
> elt0.addContent(elt1.clone());
>  
> This is currently serialized as:
>  
> <story>
>   <text>
>        Test test test <br/>
>        Test test test <br/>
>        Test test test <br/>
>   </text>
> </story>
>  
> I need it to be as follows:
>
> </story>
>   <text><![CDATA[
>        Test test test <br/>
>        Test test test <br/>
>        Test test test <br/>
>         ]]>
>   </text>
> </story>

How about this, extend XMLOutputter and override printElement

    public class MyOutputter extends XMLOutputter {

        protected void printElement(Element element, Writer out,
                                    int level, NamespaceStack stack) {
            if ((element.getName()).equals("text")) {
                out.write("<text>");
                out.write("<![CDATA[");
                outputElementContent(element, out);
                out.write("]]>");
                out.write("</text>");
            }
            else {
                super.printElement(element, out, level, stack);
            }
        }
    }

Brad



More information about the jdom-interest mailing list