XPath helps you find nodes, but not add them. I donβt think you will find it particularly useful here.
What XML interface are you using? If it is a W3C DOM (urgh), you would do something like:
Element newB = document.createElement("B"); Element newC = document.createElement("c"); newC.setTextContent("11"); Element newD = document.createElement("d"); newD.setTextContent("21"); Element newE = document.createElement("e"); newE.setTextContent("31"); newB.appendChild(newC); newB.appendChild(newD); newB.appendChild(newE); document.getDocumentElement().appendChild(newB);
source share