Listing G: NodeList example



String sColor = "red";

NodeList nodeList = XPathAPI.selectNodeList(doc,"/catalog/product[@sku='123']/colors/color]");

Node productColorsNode = XPathAPI.selectSingleNode(doc,"/catalog/product[@sku='123']/colors]");

Node deletedNode;

for (int i=0;i<nodeList.getLength();i++)

{

if(nodeList.item(i).getFirstChild().getNodeValue().toString().compareTo(sColor)==0)

     {

          deletedNode = nodeList.item(i);

           productColorsNode.removeChild(deletedNode);

      }

}