XMLSyntaxError when parsing an XML with a schema, where an attribute is declared
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
lxml |
Invalid
|
Undecided
|
Unassigned |
Bug Description
Here is a simple schema, which declares an element `root` with a single boolean attribute, named `foo`:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://
<xs:element name="root">
</xs:schema>
Here is the XML, that complies to the schema:
<?xml version="1.0"?>
<root
foo="true"
/>
And here is the Python code, that parses the XML and validates it against the schema:
import lxml
import lxml.etree
schema_parser = lxml.etree.
schema_doc = lxml.etree.
schema = lxml.etree.
parser = lxml.etree.
)
settings = lxml.etree.
It produces a strange exception: `XMLSyntaxError: Element 'root', attribute 'foo': '' is not a valid value of the atomic type 'xs:boolean'.`.
Notice `'foo': ''` part - it means, that LXML think, that the attribute is empty, for some reason.
p.s.
Versions info:
Python : sys.version_
lxml.etree : (3, 6, 4, 0)
libxml used : (2, 9, 4)
libxml compiled : (2, 9, 4)
libxslt used : (1, 1, 29)
libxslt compiled : (1, 1, 29)
description: | updated |
This looks like a more general problem with attributes.
For example, changing `type="xs:boolean" default="false"` to `type="xs:short"` and `foo="true"` to `foo="1"` above gives `lxml.etree. XMLSyntaxError: Element 'root', attribute 'foo': '' is not a valid value of the atomic type 'xs:short'.`
The failures are on Python 2.7.11, libxslt 1.1.29, libxml2 2.9.4, lxml 3.7.3.
If I switch to libxslt 1.1.28, libxml2 2.9.2, lxml 3.6.4, then both examples work fine.