开发者

How to get the default value set by the xml schema?

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.


First, you need to include you schema, using lxml.etree.XMLSchema

I think it only does validation, but you may want to try to parse your XML together with the schema and see if the "default" value appears.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜