This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to replace TextNode in XML?

 
Stan Shah
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Paul Clapham
Sheriff
Pie
Posts: 20187
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks it worked.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic