I’ve got an xml schema which specifies a default value for an optional field…
<xs:element name="expiry" type="xs:positiveInteger" default="86400"/>
I’m using lxml to parse the incoming xml…
root = lxml.etree.XML(xml)
When I go looking for the optional element, and it’s not there, I get a ‘None’ result…
expiry = root.findtext('expiry')
How would I get the expiry value to default to the schema’s default (86400)?
Can’t be done by ‘magic’. The long way is the only way (today).
That is: read the xmlschema like an xml document, find the element tag with the attribute “expiry”, look for the value of the attribute “default” in that tag.