iam使用mgwt構建移動應用程序。這個應用程序包含列表哪些內容來自xml文件。 我正嘗試通過應用程序將新內容添加到這些xml文件中。gwt將新的子節點添加到xml文件中
下面是XML文件:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<options>
<option>c1 A</option>
<option>c1 B</option>
</options>
</root>
蔭試圖將<選項>家長中添加一個新的
<option>c1 C </option>
標籤,所以結果會是這樣。
<?xml version="1.0" encoding="UTF-8"?>
<root>
<options>
<option>c1 A</option>
<option>c1 B</option>
<option>c1 C </option>
</options>
</root>
Iam用下面的代碼嘗試它,但沒有任何反應。
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.");
}
出了什麼問題?請幫忙。
該代碼將爲現有Document對象添加一個新的