• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to replace TextNode in XML?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a requirement where I need to create 2 XMLs with only one Element value (TextNode) being different and put on different MQ queues. I have already created one XML and put on a queue. Now how do I replace the Element value within that DOM Object.

E.g
--XML 1
<EMP>
<NAME>ABC</NAME>
<AGE>22</AGE>
</EMP>

Now how do I make this into
--XML 2
<EMP>
<NAME>XYZ</NAME>
<AGE>22</AGE>
</EMP>

I have org.w3c.dom.Document object holding the XML Message.

Thanks,
Stan
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'll find the problem easier when you realize the non-obvious way that DOM works. Your question ("How do I replace the Element value") is meaningless because an Element doesn't have a value. But what you want to modify is actually the Text node that is the Element's only child.

So navigate to the <NAME> element, then to its first child, which should be a Text node. Call setValue("XYZ") on that node and you're done.
 
Stan Shah
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks it worked.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic