Search code examples
javaxmljdom

how to insert value into xml?


I am really new to XML and JDOM so I have a noob question, sorry for that. I have a XML file and I want to insert value into it. My XML file is like that;

<?xml version="1.0"?>
<message>
    <header>
        <messageType>  </messageType>
        <sendFrom> </sendFrom>
        <HostName> </HostName>
        <sendTo> </sendTo>
        <receiverName> </receiverName>
        <date> </date>
    </header>
    <body>
    </body>
</message>

So what I want is for example is to add value between <sendTo> </sendTo> and also I want to add <A> data </A> between <body> </body>. Can you please tell me how to do that ?

Thanks a lot.


Solution

  • http://www.cafeconleche.org/books/xmljava/chapters/ch14s04.html

    http://www.java2s.com/Code/Java/XML/MakeupandwriteanXMLdocumentusingDOM.htm