How to get the default value set by xml schema?

I have an xml schema that indicates the default value for an optional field ...

<xs:element name="expiry" type="xs:positiveInteger" default="86400"/>

I am using lxml to parse incoming xml ...

root = lxml.etree.XML(xml)

When I search for an optional element and it does not exist, I get the result "No" ...

expiry = root.findtext('expiry')

How do I get the expiry default value for the default schema (86400)?

+3
source share
2 answers

Cannot be done by "magic." The long way is the only way (today).

That is: read xmlschema as an xml document, find the element tag with the "expiry" attribute, find the value of the "default" attribute in this tag.

+1
source

, lxml.etree.XMLSchema

, , XML , .

0

All Articles