I'm attempting to create an XML DOM document from an Input Stream using the following code. The request object if HttpServletRequest request object on a doPost call.
The last line of code gets this exception: org.xml.sax.SAXParseException: Content is not allowed in prolog.
On the post side, I've created a valid XML string that is UTF-8 encoded. Do I need to decode first before the docBuilder.parse(input) call?
Can anyone help me out?
JavaWeb Components
Last Comment
HLRosenberger
8/22/2022 - Mon
Mick Barry
whats the code sending the post look like?
HLRosenberger
ASKER
If I do the decode first then I'm OK. No exception.
Now another question: I have a document as a result of this line of code
Document doc = docBuilder.parse(input);
How do I iterate through the elements in the document? So far, every attempt I have made results in EXCEPTION: java.lang.UnsupportedOperationException: Not yet implemented
// Get the input string for the POST request object.
InputStreamReader input = new InputStreamReader(request.getInputStream());
// Get the length of the data, then create a buffer of that
// size to handle it, then read the data that was POSTed.
int read_len = request.getContentLength();
char[] cbuf = new char[read_len];
input.read(cbuf);
// Convert it to a string and decode it.
String Encoded_XML = new String(cbuf);
String XML = URLDecoder.decode(Encoded_XML, "UTF-8");