[jdom-interest] adding comments to a document object with on seperate lines

Bradley S. Huffman hip at cs.okstate.edu
Thu Oct 28 09:39:13 PDT 2004


I would extend XMLOutputter and overide printComment, printElement, and
printProcessingInstruction like this

    protected void printComment(Writer out, Comment comment) {
        super.printComment(out, comment);
        if (comment.getParent() instanceof Document) {
            out.write(getFormat().getLineSeperator());
        }
    }

Same for the other methods.

Brad

Will Luxton writes:

> Hi all,
> 
> my program is modifying existing schema objects, and
> needs to preserve spacing in the outputted document so
> that it matches the parsed input document - for this
> reason I use Format.getRawFormat(). So far so good.
> However I now need to add a number of comments to the
> document object (outside of the root element), and
> these all appear on the same line. I cannot add a
> newline marker through adding a Text object to the
> document - so that fudge is out.
> 
> Outside of changing the format for the outputter to
> Format.getPrettyFormat(), which will change the
> spacing etc of the outputted document, is there any
> way I can  get each of the comments to appear on
> seperate lines?
> 
> cheers
> 
> Will
> 
> Send instant messages to your online friends http://uk.messenger.yahoo.com 
> _______________________________________________
> To control your jdom-interest membership:
> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com


More information about the jdom-interest mailing list