how to Update/insert an xml element's text----> (<element>text</element>)

H

HANM

hello friends,
how can we update or insert into an xml Element.
For example :
-------------------

<?xml version="1.0">
<request>
<main>
<name>ISO8856</name>
</main>
</request>

here when we run a java class file it should replace "ISO8856"with
"ISO9001". Any Assistance or example.

thanQ in adv.
Ajay
 
M

Martin Honnen

HANM said:
<?xml version="1.0">
<request>
<main>
<name>ISO8856</name>
</main>
</request>

here when we run a java class file it should replace "ISO8856"with
"ISO9001". Any Assistance or example.

If you use the W3C DOM Level 3 Core as implemented in Java 1.5 and later
then you can select the 'name' element and set its textContent e.g.
Element name = (Element)xmlDocument.getElementsByTagName("name").item(0);
name.setTextContent("ISO09001");
If you use DOM Level 2 Core (as implemente in Java 1.4) then you need to
access the firstChild and set its nodeValue
Element name = (Element)xmlDocument.getElementsByTagName("name").item(0);
name.getFirstChild().setNodeValue("ISO09001");
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top