Friday, September 30, 2011

Re: Failure Parsing XML Document from Servlet

On Thursday, September 29, 2011 10:39:40 PM UTC+2, Laura Bickle wrote:
Hi Jeff,

I set the content type like so:  response.setContentType("text/xml");

I think MIME is a superset of content type.  I don't explicitly set any other MIME things.  How do I look up the MIME type of a file?

My previous errors are from firefox.  Per your suggestion, I tried using safari and chrome instead and they each gave me this error.  The first line is the result of requesting the xml file.  The second line comes from trying to parse it.

(-:-) 2011-09-29 13:32:28,825 [DEBUG] result:<?xml version="1.0" encoding="UTF-8"?><stuff>

IIRC, some browsers (can't remember which ones) choke on the XMLDecl when it specifies an encoding; because you're parsing a String, which is a stream of characters, and encodings only applies to streams of bytes (to actually turn the bytes into characters).
Try trimming the XMLDecl from your XML before giving it to XMLParser.parse().
Something like (untested):
if (xml.substring(0, 5).equalsIgnoreCase("<?xml")) {
   xml = xml.substring(xml.indexOf("?>") + 2);

Best would of course be to emit the encoding in the Content-Type HTTP header (application/xml; charset=UTF-8) and not send the XMLDecl at all.

You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

No comments:

Post a Comment