aspose file tools*
The moose likes XML and Related Technologies and the fly likes Replacing the content of a node with a text string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Replacing the content of a node with a text string" Watch "Replacing the content of a node with a text string" New topic
Author

Replacing the content of a node with a text string

Miguel Capo
Greenhorn

Joined: Oct 08, 2006
Posts: 14
Hi there,

I need to replace a couple of nodes that contain childnodes etc with just a text node. Does anybody know a quick way of doing this?

Is the best way to create a node with the same name etc but just with the text node that I want to insert and the use the replaceChild method of the Node interface? or is there a simpler way?

Thanks
[ November 03, 2006: Message edited by: Miguel Capo ]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
In the org.w3c.dom.Node class there is the
replaceNode(Node newChild, Node oldChild)
method. See the JavaDocs for details.
Bill
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
I'm in the habit of checking out the Java Developer's Almanac when I need to do something new with the DOM API. You might want to check it out, too (or bookmark it for later).


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Replacing the content of a node with a text string