• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • 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
 
He baked a muffin that stole my car! And this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic