On 8 juil, 18:53, Robert Hanson <[email protected]> wrote:
> Based on the docs for FormPanel the server has to reply with the
> content-type of text/html, otherwise there may be issues with some
> browsers.  But if you do that, and send XML content it seems it has browser
> issues.
>
> For example, in FF/DevMode the SubmitCompleteEventHandler returns null for
> the result.  In Chrome is returns the XML content, but it is malformed.
> Some elements like <link /> were in the results as <link>, causing XML
> parsing issues.
>
> One solution I found was to return the XML as an HTML comment, prefixed by
> some fake content.
>
> For example, instead of this:
> <?xml version='1.0' encoding='UTF-8'?><feed>...</feed>
>
> I returned this:
> content<!--<?xml version='1.0' encoding='UTF-8'?><feed>...</feed>-->
>
> I can then remove the prefix "content<!--" and postfix "-->" text, and parse
> what remains as XML.
>
> Other than the fact that I don't handle the possibility of comments within
> the XML content, is there any other potential issues?  Or maybe there is a
> better way?
>
> The only requirement for what I am working on is that it must use a
> FormPanel submission, and parse the XML returned from the server.

I would HTML-escape the XML (&lt;feed>...&lt;/feed>, you don't
actually want the <?xml?> decl) on the server-side, and use a
setInnerHTML/getInnerText on an element to unescape it on the client-
side.

public void onSubmitComplete(SubmitCompleteEvent event) {
   String escapedXML = event.getResult();
   DivElement div = Document.get().createDivElement();
   div.setInnerHTML(escapedXML);
   String xml = div.getInnerText();
   // now you can use XMLParser
}

The other option of course is to send enough information so you can
get the XML from another request (RequestBuilder or GWT-RPC).

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to