0

I have xml file with tag as following :

<sometag/>

I want to modify this tag as following :

<sometag>somevalue</sometag>

initially I tried to delete element and create new element, that doesnt work. then I get to know that there is already a method to rename a tag, I tried following code, but dont know how to add value (somevalue) for this renamed element(sometag).

NodeList scpNodes=doc.getElementsByTagName("sometag");
    for (int i = 0; i < scpNodes.getLength(); i++) {
        Element toBeReplaced=(Element) scpNodes.item(i);
        doc.renameNode(toBeReplaced, toBeReplaced.getNamespaceURI(),"sometag");        
     // how to append value ?
    }
3
  • 1
    Do you mean <sometag>somevalue</sometag>? Commented Aug 5, 2015 at 10:58
  • did the answer below solved your problem ? Commented Aug 5, 2015 at 14:36
  • yes, its working fine, thanks for help !! Commented Aug 6, 2015 at 3:06

1 Answer 1

1

you have to call

toBeReplaced.setTextContext("someValue");

and get rid of

doc.renameNode(toBeReplaced, toBeReplaced.getNamespaceURI(),"sometag");  
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.