[lxml-dev] resolve_entities=False seems to have no effect

Stefan Behnel stefan_ml at behnel.de
Sat Feb 7 13:34:27 CET 2009


> s = cStringIO.StringIO("""<foo>&quot;She&apos;s the MAN!&quot;</foo>""")
> e = etree.parse(s,etree.XMLParser(resolve_entities=False))

Note that there's also etree.fromstring().


> etree.tostring(e)
> '<foo>"She\'s the MAN!"</foo>'
>
> I would have expected resolve_entities=False to have prevented the
> translation of, eg, &quot; to ".

The "resolve_entities" option is meant for entities defined in a DTD of
which you want to keep the reference instead of the resolved value. The
entities you mention are part of the XML spec, not of a DTD.


> is there another way to prevent this behavior (or, if nothing else,
> reverse it after the fact)?

Well, what you get is well-formed XML. May I ask why you need the entity
references in the output?

Stefan


More information about the lxml-dev mailing list