To build an XML tree that describes an item
// create elements
Element itemElement = doc.createElement("item");
Element productElement = doc.createElement("product");
Element descriptionElement =
doc.createElement("description");
Element priceElement = doc.createElement("price");
Element quantityElement =
doc.createElement("quantity");
Text descriptionText =
doc.createTextNode("Ink Jet Refill Kit");
Text priceText = doct.createTextNode("29.95");
Text quantityText = doc.createTextNode("8");
// add elements to the document
doc.appendChild(itemElement);
itemElement.appendChild(productElement);
itemElement.appendChild(quantityElement);
productElement.appendChild(descriptionElement);
productElement.appendChild(priceElement);
descriptionElement.appendChild(descriptionText);
priceElement.appendChild(priceText);
quantityElement.appendChild(quantityText);