[jdom-interest] encoding problem converting XML document to string
William Krick
wkrick at eio-online.com
Wed Nov 5 12:50:56 PST 2003
First off, I'm not sure what version of JDOM I am using. It's the version
that comes with JBuilder9. It would be convenient if you could double click
on the JDOM jar and have it pop up a window with version info. I've seen
this done with other libraries (J2PrinterWorks comes to mind).
My current platform is Windows if it matters.
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);
String xml = null;
try {
xml = outputter.outputString(doc);
}
catch (IOException ex) {
System.out.println(ex);
ex.printStackTrace();
}
return xml;
}
I have code that reads in an XML file using a fileInputStream
and SAXBuilder to create a Document object.
In case it matters, my XML file is indented with two space indents and 0D 0A
(carrige return, linefeed) newlines after each line.
Then I call my method above to convert it into a string.
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?
Why is there any whitespace at all in the output?
...
Krick
More information about the jdom-interest
mailing list