11
Answers

add a new node to xml data

Ask a question
darma teja

darma teja

11y
1.1k
1
Hi All,

My xml file is like this:

<?xml version="1.0" encoding="ISO-8859-1"?>
 - <note>
    <step ID="1">
       <to><to1>Tove<to1></to>
       <from>Jani</from>  
    </step>     
    <step ID="2">
        <to><to1>Tove1<to1></to>
       <from>Jani1</from>
  </step> 
 <step ID="3">
        <to><to1>Tove2<to1></to>
       <from>Jani2</from>
 </step> 
</note>

I want to add a new node (<check>ok</check>) to where ID= 2

my xpath is: note/step[ID='2']/to/

final result should be like this in xml file:

 <step ID="2">
        <to>
           <to1>Tove1<to1>
           <check>ok</check>
       </to>
       <from>Jani1</from>
 </step> 


Thanks
Darma





Answers (11)