[4suite] Printers (cued)

Alexandre Fayolle alf at logilab.com
Tue Sep 19 11:17:48 MDT 2000


We have another problem with printers, but maybe it's something much
deeper and parsers are involved. We know that Sax2.FromXml eats XML
comments. This is a bit annoying since a FromXml followed by a PrettyPrint
will loose comments in a file. However, we can cope with it, because the
real XML content of the file is somehow preserved. Once you know that, you
can take care of what you do and avoid comments in 'sensible' files. 

Something more annoying are the xml header and doctype of the file. One of
my co-workers signaled me that when a file with a doctype is FromXML'ed
and Print'ed back, the doctype declaration is lost. I have reproduced it,
but I have not had time to investigate further to know if the doctype is
present in the DOM tree but not Printed, or if the Sax parser garbles it
as it does with comments. This is a more serious issue, for which we shall
have to find a workaround, probably be writing a wrapper around
(Pretty)Print. 

Another minor issue has to do with (Pretty)Printing document fragments:
>>> PrettyPrint(d.documentElement.childNodes)
Traceback (innermost last):
  File "<stdin>", line 1, in ?
  File "/home/alf/xmlSig/repository/xml/xml/dom/ext/__init__.py", line
206, in PrettyPrint
    if root.ownerDocument.isHtml():
  File "/home/alf/xmlSig/repository/xml/xml/dom/NodeList.py", line 109, in
__getattr__
    return getattr(NodeList, name)
AttributeError: ownerDocument

using Print goes a bit further but still fails:

>>> Print(d.documentElement.childNodes)
Traceback (innermost last):
  File "<stdin>", line 1, in ?
  File "/home/alf/xmlSig/repository/xml/xml/dom/ext/__init__.py", line
190, in Print
    st = Printer.PrintWalker(visitor, root).run()
  File "/home/alf/xmlSig/repository/xml/xml/dom/ext/Printer.py", line 613,
in run
    return self.step()
  File "/home/alf/xmlSig/repository/xml/xml/dom/ext/Printer.py", line 609,
in step
    st = self.visitor.visit(self.start_node)
  File "/home/alf/xmlSig/repository/xml/xml/dom/ext/Printer.py", line 271,
in visit
    raise "Unknown node type: Node=" + str(node)
Unknown node type: Node=<NodeList at 136203072: [<Element Node at
134878392: Name = 'elt' with 1 attributes and 0 children>]>

However, in PrintVisitor, a visitNodeList() method is provided. It's just
forgotten in visit()

-- 
Alexandre Fayolle
http://www.logilab.com - "Mais o est donc Ornicar ?" - 
LOGILAB, Paris (France).




More information about the 4suite mailing list