No line number when XmlSchema used in XMLParser
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
lxml |
Confirmed
|
Undecided
|
Unassigned |
Bug Description
When passing an XMLSchema to the XMLParser constructor and then reading invalid XML, the XMLSyntaxError message doesn't contain the proper line number of the XML document. The stack trace always shows "File "<string>", line 0", regardless of where the error actually is.
See attached example, which is based on sniplets from:
https:/
python3 pyGen/xmlValida
Traceback (most recent call last):
File "pyGen/
root = etree.fromstring(
File "src/lxml/
File "src/lxml/
File "src/lxml/
File "src/lxml/
File "src/lxml/
File "src/lxml/
File "src/lxml/
File "<string>", line 0
lxml.etree.
Workaround: Instead of passing the XMLSchema to the XMLParser, parse the document without a schema, then call schema.
parser = etree.XMLParser()
root = etree.fromstring(
'''<a>
<c></c>
</a>''', parser)
schema = etree.XMLSchema
schema.
Traceback (most recent call last):
File "pyGen/
schema.
File "src/lxml/
lxml.etree.
Python : sys.version_
lxml.etree : (4, 9, 1, 0)
libxml used : (2, 9, 14)
libxml compiled : (2, 9, 14)
libxslt used : (1, 1, 35)
libxslt compiled : (1, 1, 35)
Changed in lxml: | |
status: | New → Confirmed |
The same problem occurs when using etree.parse() instead of etree.fromstring().