[4suite] Bug in (Pretty)Print ?
Nicolas Chauvat
nico at logilab.com
Thu Sep 21 06:29:24 MDT 2000
File test.xml is a one-liner:
<xsltemplate match="email/headers[substring-after(subject,'address')]"/>
Then try this:
>>> from xml.dom.ext.reader import Sax2
>>> a = Sax2.FromXmlFile('test.xml')
>>> Print(a)
<xsltemplate match='email/headers[substring-after(subject,'address')]'/>
Notice the simple quote that replaced the double quotes ? That makes
trouble if you then try to re-read the string using Sax2:
>>> from xml.dom.ext.reader import Sax2
>>> a = Sax2.FromXmlFile('test.xml')
>>> import StringIO
>>> s = StringIO.StringIO()
>>> Print(a,s)
>>> b = Sax2FromXml(s.getvalue())
Traceback (innermost last):
File "<stdin>", line 1, in ?
File "/usr/lib/python1.5/site-packages/xml/dom/ext/reader/Sax2.py", line
410, in FromXml
rv = FromXmlStream(fp, ownerDocument, validate, keepAllWs, catName,
saxHandlerClass)
File "/usr/lib/python1.5/site-packages/xml/dom/ext/reader/Sax2.py", line
400, in FromXmlStream
parser.parseFile(stream)
File "/usr/lib/python1.5/site-packages/xml/sax/drivers/drv_pyexpat.py",
line 80, in parseFile
self.__report_error()
File "/usr/lib/python1.5/site-packages/xml/sax/drivers/drv_pyexpat.py",
line 96, in __report_error
self.err_handler.fatalError(saxlib.SAXParseException(msg,None,self))
File "/usr/lib/python1.5/site-packages/xml/dom/ext/reader/Sax2.py", line
380, in fatalError
raise exception
xml.sax.saxlib.SAXParseException: not well-formed at :1:59
Simple work-around is "always use single quotes when defining attributes
in your xml files".
I checked the spec and
http://www.w3.org/TR/1998/REC-xml-19980210.html#NT-AttValues says:
[10] AttValue ::= '"' ([^<&"] | Reference)* '"'
| "'" ([^<&'] | Reference)* "'"
I suppose it's (Pretty)Print that has to be fixed.
--
Nicolas Chauvat
http://www.logilab.com - "Mais o est donc Ornicar ?" - LOGILAB, Paris (France)
More information about the 4suite
mailing list