W3C home > Mailing lists > Public > www-dom@w3.org > April to June 1999

Re: Modifying the text component of a DOM Node

From: David Brownell <db@argon.Eng.Sun.COM>
Date: Tue, 6 Apr 1999 17:50:49 -0700
Message-Id: <199904070050.RAA09898@argon.eng.sun.com>
To: byrnes@prl.research.philips.com, www-dom@w3.org
Cc: xml-feedback@java.sun.com
> 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

This archive was generated by hypermail 2.3.1 : Tuesday, 20 October 2015 10:46:05 UTC