Launchpad

XML 1.0 standard specifies that document type declaration system literal must be of the form

('"' [^"]* '"') | ("'" [^']* "'")

[http:// www.w3. org/TR/ REC-xml/ #sec-prolog- dtd]

That is, it is anything that starts and ends with hyphen, or starts and ends with quote.
Especially, it may be a string which starts with hyphen, contains a quote, and end swith hyphen.
That is, these both are valid:

<!DOCTYPE a PUBLIC 'foo' '"'><a/>
<!DOCTYPE a SYSTEM '"'><a/>

However, both cases break lxml:
>>> import lxml.etree
>>> doc = lxml.etree. XML(''' <!DOCTYPE a PUBLIC 'foo' '"'><a/ >''').getroottr ee()
>>> doc.docinfo.doctype
u'<!DOCTYPE a PUBLIC "foo" """>'
>>> lxml.etree. tostring( doc)
'<!DOCTYPE a PUBLIC "foo" """>\n<a/>'
>>>
>>> doc = lxml.etree. XML(''' <!DOCTYPE a SYSTEM '"'><a/ >''').getroottr ee()
>>> doc.docinfo.doctype
u'<!DOCTYPE a SYSTEM """>'
>>> lxml.etree. tostring( doc)
'<!DOCTYPE a SYSTEM """>\n<a/>'

Read the original on bugs.launchpad.net ↗