[XML-SIG] (Py)DOM: Character References

Fred L. Drake Fred L. Drake, Jr." <fdrake@acm.org
Thu, 18 Mar 1999 10:31:30 -0500 (EST)


Carsten Oberscheid writes:
 > Can anybody tell why character references are not modeled explicitely in the 
 > DOM? In XML they have their own identity, explicitely distinct from entity 

Carsten,
  Good question.  I don't know why character references need explicit
nodes in the DOM; I'm not terribly interested in knowing that
something was encoded as "&#43;" or "+".  I would like to be able to
have this:

<!DOCTYPE thing>
<thing>&foo;</thing>

provide a reference to &foo; as a child of the <thing> node.  Here's
what I get now:

>>> buffer = '<!DOCTYPE thing>\n<thing>&foo;</thing>'
>>> import xml.dom.utils
>>> reader = xml.dom.utils.FileReader()
>>> import cStringIO
>>> sio = cStringIO.StringIO(buffer)
>>> dom = reader.readStream(sio)
>>> dom.documentElement
<Element 'thing'>
>>> len(dom.documentElement.childNodes)
0

And here's a bug ;-) :

>>> dom.documentElement.childNodes
<NodeList]>


  -Fred

--
Fred L. Drake, Jr.	     <fdrake@acm.org>
Corporation for National Research Initiatives