[jdom-interest] encoding problem converting XML document to string
William Krick
wkrick at eio-online.com
Thu Nov 6 07:25:26 PST 2003
> -----Original Message-----
> From: jdom-interest-admin at jdom.org
> [mailto:jdom-interest-admin at jdom.org]On Behalf Of Bradley S. Huffman
> Sent: Wednesday, November 05, 2003 8:11 PM
> To: William Krick
> Cc: jdom-interest at jdom.org
> Subject: Re: [jdom-interest] encoding problem converting XML document to
> string
>
>
> "William Krick" writes:
>
> > I have a method that converts an XML document to a string...
> >
> > public static String docToString(Document doc) {
> > // build a string from an XML document
> > XMLOutputter outputter = new XMLOutputter("",false);
>
> The above line says XMLOutputter will not try to pretty print (the false
> for the newlines argument). Hmmm, old B7 javadocs for setNewlines seems
> misleading.
>
> > The resulting string looks like this...
> >
> > <?xml version="1.0" encoding="UTF-8"?><NYPA>\u000a
> <NUMVEHICLES>1 etc...
> >
> > Why are my CRLF being replaced with "\u000a" and two spaces?
>
> That's done by the XML parser per the spec.s section 2.11 "End-of-Line
> Handling". Basically all CR/LF are normalized to a single LF (\u000a).
>
> > Why is there any whitespace at all in the output?
>
> See above comment about the constructor. What are you wanting your output
> to look like? If whitespace is unimportant in your app., and your version
> of JDOM is B8 or above, look at doing
>
> XMLOutputter outputter = new XMLOutputter();
> outputter.setTextNormalize(true);
Thanks for your help.
Unfortunately, setTextNormalize isn't supported in my version of JDOM
What I really need is to go from human readable formatted XML
ASCII file to an XML string with no whitespace.
The steps in between are not really important to me.
I may end up having to skip the JDOM all together and just read the file a
line at a time, trim leading and trailing whitespace, and append it to a
string buffer.
...
Krick
More information about the jdom-interest
mailing list