Vote count:
0
I try to retrieve XML data from an external server and to display informations on my GWT application.
The problem is that I don't succeed to display the xml informations.
my java code :
protected void retrieveXmlDataTop(final VerticalPanel c) {
url = "http://ift.tt/1GwDnKJ";
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,URL.encode(url));
try
{
builder.sendRequest(null, new RequestCallback() {
@Override
public void onError(Request request, Throwable exception) {
// Couldn't connect to server (could be timeout, SOP
// violation, etc.)
Window.alert("Couldn't retrieve XML");
}
@Override
public void onResponseReceived(Request request, Response response) {
if (200 == response.getStatusCode())
{
// Process the response in response.getText()
parseMessage(c , response.getText());
}
else
{
// Handle the error. Can get the status text from
// response.getStatusText()
//Window.alert("Error: " + response.getStatusText());
Label error = new Label("Error");
c.add(error);
}
}
});
}
catch (RequestException e)
{
// Couldn't connect to server
Window.alert("Couldn't connect to server to retrieve the XML: \n");
}
}
private void parseMessage(final VerticalPanel c, String messageXml)
{
try
{
// parse the XML document into a DOM
Document messageDom = XMLParser.parse(messageXml);
String tag1Value = messageDom.getElementsByTagName("ranking").item(0)
.getFirstChild().getNodeValue();
String tag2Value = messageDom.getElementsByTagName("title").item(0)
.getFirstChild().getNodeValue();
//Window.alert("Ranking Value: " + tag1Value + "\n" + "Title Value: " + tag2Value);
Label result = new Label("Ranking Value: " + tag1Value + "\n" + "Title Value: " + tag2Value);
c.add(result);
}
catch (DOMException e)
{
Window.alert("Could not parse XML document.");
}
}
And my xml page :
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<movies>
<movie>
<idIMDB>tt0111161</idIMDB>
<ranking>1</ranking>
<rating>9.2</rating>
<title>The Shawshank Redemption</title>
<urlPoster>http://ift.tt/1GwDnKL;
<year>1994</year>
</movie>
</movies>
I obtain always the message "Error".
Thank you for your help
Mickey74
asked 44 secs ago
GWT retrieve XML data on server
Aucun commentaire:
Enregistrer un commentaire