[lxml-dev] Is resolve_entities not working ??

Stefan Behnel stefan_ml at behnel.de
Mon Feb 18 21:06:37 CET 2008


Hi,

Steve Howe wrote:
> Is the resolve_entities XmlParser constructor attribute not working or what 
> did I do wrong ?
> 
> howe at yezda ~ $ python
> Python 2.5.1 (r251:54863, Jan  9 2008, 05:34:21)
> [GCC 4.2.2 (Gentoo 4.2.2 p1.0)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> from lxml import etree
>>>> print etree.__version__
> 2.0.1
>>>> print etree.LIBXML_VERSION
> (2, 6, 30)
>>>> import StringIO
>>>> xml = StringIO.StringIO('<?xml version="1.0" encoding="utf-8"?> 
> <p>&copy;</p>')
>>>> etree.parse(xml, etree.XMLParser(resolve_entities=False))
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "lxml.etree.pyx", line 2515, in lxml.etree.parse
>   File "parser.pxi", line 1743, in lxml.etree._parseDocument
>   File "parser.pxi", line 1775, in lxml.etree._parseMemoryDocument
>   File "parser.pxi", line 1676, in lxml.etree._parseDoc
>   File "parser.pxi", line 793, in lxml.etree._BaseParser._parseDoc
>   File "parser.pxi", line 450, in 
> lxml.etree._ParserContext._handleParseResultDoc
>   File "parser.pxi", line 534, in lxml.etree._handleParseResult
>   File "parser.pxi", line 476, in lxml.etree._raiseParseError
> lxml.etree.XMLSyntaxError: Entity 'copy' not defined, line 1, column 46

As the document does not specify a DTD, the entity "copy" is undefined, which
is an error if you instructed the parser to *resolve* the entities.

Stefan


More information about the lxml-dev mailing list