Here is the xml i am working on :
<stan:standardHeader>
<stan:serviceState>
<stan:stateCode/>
</stan:serviceState>
<stan:serviceAddressing>
<stan:from>
http://www.profile.com?BTCOM</stan:from>
</stan:serviceAddressing>
</stan:standardHeader>
<manageClientProfileReq>
<man:clientProfile>
<get:client>
<user:id/>
<ccm:action>delete</ccm:action>
<user:clientIdentifier>
<user:value/>
</user:clientIdentifier>
<user:clientIdentity>
<ccm:updateKey/>
<ccm:action>vikash</ccm:action>
<user:managedIdentifierDomain>
<res:value>FVC</res:value>
</user:managedIdentifierDomain>
</user:clientIdentity>
</get:client>
</man:clientProfile>
</manageClientProfileReq>
I have to remove the value in the tag <ccm:action></ccm:action> ; the one that is in the <get:client> tag .
Here Is the code i am using :
NodeList parentNodeList = document.getElementsByTagName("get:client");
for (int i = 0; i < parentNodeList.getLength(); i++)
{
Node parentNode = parentNodeList.item(i);
Element parentElement = (Element)parentNode ;
if(parentNode.getNodeType() == Node.ELEMENT_NODE)
{
NodeList childNodeList = parentElement.getElementsByTagName("ccm:action");
for(int j=0 ; j < childNodeList.getLength() ; j++)
{
Node childNode = childNodeList.item(0);
parentElement.removeChild(childNode);
Element newNode = document.createElement("ccm:action");
parentElement.appendChild(newNode);
System.out.println(" A new node was created ");
}
}
This shows an error :
NOT_FOUND_ERR: An attempt is made to reference a node in a context where it does not exist.
How can i remove value in that tag without this error ?
This approach was used since i could not simply remove the value in the tag however thats the actual requirement . This one works but for that the new node replacing the earlier one cant have the same name . Please help .