0

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.

Pero
  • 774
  • 3
  • 15
  • 34
  • That code will add a new – Chepech Oct 22 '13 at 00:45

1 Answers1

1

If you are running your code inside a phonegap container GWT.getHostPageBaseURL() will point to file://somepath on your device. I am guessing that you want to load the data from the server. You will need to use a proper url.

On the other hand you should be aware that XML processing in a browser is pretty slow and should consider using JSON as an alternative format.

Daniel Kurka
  • 7,973
  • 2
  • 24
  • 43
  • No, the highest part of the app consists of cellLists and the content, which is represented in these celllists, comes from XML files which are stored in the war folder of the mgwt project respectively in the assets/www folder of the android-mgwt-app. The content of the xml files is loaded via RequestBuilder into the CellLists. I want to add some new datas, through the app into these xml files. And these new informations should be displayed in the celllists after refresh. – Pero Jun 26 '13 at 18:17