OutputStreamWriter outStream = new OutputStreamWriter(new BufferedOutputStream(conn.getOutputStream()),"UTF-8"); outStream.write(xmlRequestString); outStream.close();
I've left out some of the finer details, but the request works fine.
When a CDATA node is returned with a large amount of formatted binary data in the response XML document, the text is always squashed onto 2 lines, essentially losing the layout of the CDATA contents (in this case, a text report).
eg. Correct formatting: <CDATA[[ report
company 45393987398 figures 983983983983 blah blah 1023848484 hello ]]>
eg. Actual formatting: <CDATA[[report company 45393987398 figures 983983983983blah blah 1023848484 hello]]>
I have verified that the XML being sent to me is ok as I have pulled it using the ServerXMLHTTP object via asp - the report comes back fine, all formatting correct.
Here are the two ways I have tried to retreive the XML response in java:
InputStream is = conn.getInputStream(); InputStreamReader isr = new InputStreamReader(is,"UTF-8"); BufferedReader in = new BufferedReader(isr); StringBuffer contents = new StringBuffer();
org.xml.sax.ContentHandler handler = new MySAXHandler(); parser.setContentHandler(handler);
InputStream in = conn.getInputStream(); InputSource source = new InputSource(in); parser.parse(source);
In both cases, the entire XML document is received over http, but the formatting in the CDATA node is lost. I have done a test whereby I save the correctly formatted XML document to a file on the disk and try to parse from the local file instead of a stream, and IT WORKS FINE! Seems to be an issue with how the stream is pulling in the XML document.
I am really out of ideas and wondered if anybody had some suggestions on what I can try?