I use com.google.gwt.xml.client.*.
I need to create title elements in the beginning of XML and inside the item blocks. But when I select createElement("title") and appendChild(title), I get only one Element title in the end.
private void formXMLToSend(){
Document doc = XMLParser.createDocument();
Element root = doc.createElement("rss");
root.setAttribute("version", "2.0");
doc.appendChild(root);
Element chl = doc.createElement("channel");
root.appendChild(chl);
Element title = doc.createElement("title");
title.appendChild(doc.createTextNode("sitename"));
Element link = doc.createElement("link");
link.appendChild(doc.createTextNode("http://mysite.com"));
chl.appendChild(title);
chl.appendChild(link);
for(int i = 0; i < items.size(); i++){
Element item = doc.createElement("item");
Element subTitle = doc.createElement("title");
title.appendChild(doc.createTextNode(items.get(i).getName()));
Element descr = doc.createElement("description");
descr.appendChild(doc.createTextNode(items.get(i).getText()));
item.appendChild(title);
item.appendChild(descr);
chl.appendChild(item,link);
}
Window.alert(doc.toString());
}
To test it, put the following in a GWTTestCase
The following above code fragment will produce the xml below