Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

modifying the value of the node

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how can we modify the value of the node using jaxp api
suppose i have a tag
<read>Reading xml files</read>
i have to updathe value to writing xml files
i have used setNodeValue("new string")
but no use.please tell me how to resolve this
my code for writing this is document.createElement("read");
Text val= document.createTextNode("Reading xml files")
and add both of the elements to the root element
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you have this structure:
<read>Reading xml files</read>

What you have is an org.w3c.dom.Element which has a single Child Node that is of type TEXT_NODE.
SO - in order to change the value, starting with the Element, you have to get the Node with getFirstChild() then setNodeValue("the new text")

Note that if you do a getNodeValue() on the Element, you get null.

I always find the table in the Javadocs for org.w3c.dom.Node to be extremely valuable.
Bill
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic