[lxml-dev] Problem with XMLSchema and attribute_defaults

Stefan Behnel stefan_ml at behnel.de
Mon Apr 27 13:08:15 CEST 2009


Frank Millman wrote:
> I need to validate an xml document with a schema, and at the same time
> populate it with any default attributes. This works correctly with
> minixsv,
> but it is rather slow, so I am trying lxml. It validates correctly, but I
> cannot get it to load the default attributes.
>
> This is what I am doing -
>
>     schema = etree.XMLSchema(file='bpmnxpdl_31.xsd')
>     parser = etree.XMLParser(schema=schema, attribute_defaults=True)
>     root = etree.parse('order.xml', parser)

The "attribute_defaults" flag is currently only used for DTDs. Enabling
the same for XML Schema would require setting the
"XML_SCHEMA_VAL_VC_I_CREATE" option on the schema validation context,
which doesn't seem to work for older (<=2006) libxml2 versions and is not
currently done for newer versions. Could you file a feature request for
this, so that it doesn't get lost?

Thanks,

Stefan



More information about the lxml-dev mailing list