Simple-typed elements accept any attributes
Brought to you by:
pabigot
When an element is defined in the schema as having simple type, the resulting binding class accepts attributes on that element.
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="root" type="xsd:string"/>
</xsd:schema>
$ pyxbgen --version
pyxbgen from PyXB 1.1.3
$ pyxbgen -u root.xsd -m root
urn:uuid:13b5432e-436d-11e1-bbae-20cf303045b5
Python for AbsentNamespace0 requires 1 modules
Saved binding source to ./root.py
<?xml version="1.0" encoding="utf-8"?>
<root foo='boo'/>
import root
root.CreateFromDocument(file('test.xml').read())
Should throw an exception to the effect that foo is not an allowed attribute for root.
No exception is thrown. I have not found any way to access the attribute value.
This doesn’t work either:
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="root">
<xsd:simpleType>
<xsd:restriction base="xsd:string"/>
</xsd:simpleType>
</xsd:element>
</xsd:schema>
Although this does:
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="root">
<xsd:complexType>
<xsd:simpleContent>
<xsd:restriction base="xsd:string"/>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
</xsd:schema>
$ python test.py
…
pyxb.exceptions_.UnrecognizedAttributeError: Attribute foo is not permitted in type None
Thanks for the test case. Patch available in branch next. See related issue #117, which will be reviewed in preparation for 1.1.4 (whenever that may be).
commit 382685fee22bf7e15b1823fc4c0b2d828eeef1b5
Author: Peter A. Bigot <pabigot@…>
Date: Fri Jan 20 11:13:05 2012 -0600
Nice response time, thanks.