iam building a mobile app with mgwt. This app consists of list which content comes from xml files. I am trying to add new content into these xml files through the app.
Here is the xml file:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<options>
<option>c1 A</option>
<option>c1 B</option>
</options>
</root>
Iam trying to add a new
<option>c1 C </option>
tag within the < options > parents, so the result would be this.
<?xml version="1.0" encoding="UTF-8"?>
<root>
<options>
<option>c1 A</option>
<option>c1 B</option>
<option>c1 C </option>
</options>
</root>
Iam trying it with the following code, but nothing happens.
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, GWT.getHostPageBaseURL()+"folderName/fileName.xml");
try{
builder.sendRequest(null, new RequestCallback() {
@Override
public void onResponseReceived(Request request, Response response) {
Document document = XMLParser.parse(response.getText());
Element elementRoot = document.getDocumentElement();
Element options = (Element)elementRoot.getElementsByTagName("options").item(0);
Element optionElement = document.createElement("option");
optionElement.appendChild(document.createTextNode("c1 C"));
options.appendChild(optionElement);
}
@Override
public void onError(Request request, Throwable exception) {
}
});
}catch(RequestException e){
Window.alert("Unable to build the request.");
}
what is wrong? Please help.