Question

I am trying to add a carriage return character and line feed character to format XML so that each element appears on its own line in MS Notepad.

I have tried what was suggested here: How to pretty print XML from Java?. Which adds a line feed character after each closing element. For more sophisticated editors like richText and gedit etc. the line feed character is enough. However, in notepad I seem to require a carriage return also in order to get each element on it's own line.

Is there a way to introduce that by altering a Document Transformer properties? If not is there a way to do this without have to parse the whole XML document and add them in manually?

Was it helpful?

Solution

You could make your own implementation of Writer that wraps an existing Writer / OutputStream, and replaces "\n" with "\r\n" on the fly while writing. If whitespace isn't significant in the XML text, this should be good enough. Then, pass instances of your wrapper to the code that outputs XML.

OTHER TIPS

Just do a simple replace all on \>< with >^p< where the ^p is the ParagraphMark in Special formatting in MS Word.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top