[XML-SIG] Experiences with xml-0.5
Dieter Maurer
dieter@handshake.de
Wed, 30 Dec 1998 19:39:28 +0100
This is a multi-part MIME message.
--------------FC5583E803777E8ABB8C4995
Content-Type: text/plain; charset=iso-8859-1
Based on our xml-0.5 release, I have made a small tool which adds
a hierarchical content table to HTML documents:
URL:http://www.handshake.de/~dieter/pyprojects/addContentTable.html
I encountered three bugs:
1. "xml.dom.core.Document"s methods "get_firstChild" and
"get_lastChild" (inherited from "xml.dom.core.Node")
fail to initialize the "ownerDocument" in the children
correctly (patch attached).
2. "xml.dom.write.OutputStream.write" folds successive '\n'
into a single '\n' (i.e. it eliminates empty lines).
This is bad for preformatted elements (patch attached).
3. The "NodeList" returned by "get_childNodes" is live (as
required by the standard).
This can make children processing a bit hasardous (the downside
of liveness), e.g.
f= dom.createDocumentFragment()
for c in node.childNodes: f.appendChild(c)
will *NOT* put all children of "node" into "f" (it does for
about every second, and leaves the remaining children)
because the list is modified as a side effect.
This is a well known problem with Pythons for loop.
However, the standard workaround (using a slice copy
of the list) does not work in this case, because
"NodeList[:]" does not yield a NodeList but rather
a "_nodeData".
Dieter
--------------FC5583E803777E8ABB8C4995
Content-Type: application/x-patch; name="docowner.pat"
Content-Description: Patch to provide "xml.dom.core.Document" its own
implementation of "get_firstChild" and "get_lastChild"
correctly initializing "ownerDocument" of the
children.
--- :core.py Tue Dec 29 10:45:25 1998
+++ core.py Tue Dec 29 14:59:35 1998
@@ -1041,6 +1041,27 @@
def get_childNodes(self):
return NodeList(self._node.children, self, self)
+ ## DM: the inherited method fails to set "._document" correctly
+ def get_firstChild(self):
+ """Return the first child of this node. If there is no such node, this
+ returns null."""
+
+ if self._node.children:
+ n = self._node.children[0]
+ return NODE_CLASS[ n.type ] (n, self, self)
+ else:
+ return None
+
+ ## DM: the inherited method fails to set "._document" correctly
+ def get_lastChild(self):
+ """Return the last child of this node. If there is no such node, this
+ returns null."""
+ if self._node.children:
+ n = self._node.children[-1]
+ return NODE_CLASS[ n.type ] (n, self, self)
+ else:
+ return None
+
def get_documentElement(self):
"""Return the root element of the Document object, or None
if there is no root element."""
--------------FC5583E803777E8ABB8C4995
Content-Type: application/x-patch; name="emptyline.pat"
Content-Description: Patch to remove empty line removal in "xml.dom.writer"
--- :writer.py Tue Dec 29 10:45:27 1998
+++ writer.py Wed Dec 30 11:51:50 1998
@@ -16,7 +16,9 @@
def write(self, s):
#print 'write', `s`
- self.file.write(re.sub('\n+', '\n', s))
+ #self.file.write(re.sub('\n+', '\n', s))
+ # removing newlines is not a good idea for 'pre', e.g.
+ self.file.write(s)
if s and s[-1] == '\n':
self.new_line = 1
else:
--------------FC5583E803777E8ABB8C4995--