Listing F



Node ndNewColor = doc.createElement("color");

ndNewColor.appendChild(doc.createTextNode("red"));

Node ndSize = XPathAPI.selectSingleNode(doc,"/catalog/products[@sku='123']/size]");

ndSize.getParentNode().insertBefore(ndSize, ndNewColor);