Re: Modifying the text component of a DOM Node

> for example, ie, this xml document:
> 
> <myDoc>this is some <emph>emphasis</emph></myDoc>
> 
> gets transformed to:
> 
> <myDoc>this is some emphasis</myDoc>
>
> The approach which I am using is:
> 
> 1. Get the text associated with the <emph> node.
> 2. append it to the text component of the <myDoc> node
> 3. delete the <emph> node

Simplest is to 
 
  1. Get the TEXT node child of the "emph" node.
  2. Get the parent of that "emph" node.
  2. Use parent.replaceChild() to replace the "emph" node with the text.


> The trouble is with the setNodeValue(String) method in the Node
> interface of Sun's API. I call it in the setTextInNode(Node n, String
> newText) method, but the print outs I have in the copyIntoParent(Node)
> method show that it has no affect.

Right, DOM does not specify any behavior other than not throwing
any exception in this case ... perhaps it's annoying, but that's
how it's specified.  (The only exception that can be thrown is for
a read-only node; since that element isn't read-only, it mustn't
be thrown there.)

- Dave

Received on Tuesday, 6 April 1999 21:04:48 UTC