- To create an element use createElement method and pass it a tag
Element priceElement = doc.createElement("price");
- Use setAttribute method to add an attribute to the tag
priceElement.setAttribute("currency", "USD");
- To create a text node, use createTextNode and pass it a string
Text textNode = doc.createTextNode("29.95");
- Then add the text node to the element:
priceElement.appendChild(textNode);