XSD: default value of a missing element

后端 未结 2 1036
隐瞒了意图╮
隐瞒了意图╮ 2021-01-11 16:18

Is it possible to define a default value for a missing element in an XML Schema. I have the following snippet:



        
相关标签:
2条回答
  • 2021-01-11 16:48

    call this function

    def _get_(x):
      if x is not None:
         return(x.text)
      else:
        # print('Setting Blank')
         return ''
    _get_(parent.find('childtag'))
    
    0 讨论(0)
  • 2021-01-11 16:51

    No. XSD doesn't provide for that.

    You can specify the default value of an element. But once it is missing (when that's allowed by the content model of its parent), any requests to that element will return either empty string or null (or just an error). The missing element is non-existent element!

    For attributes it is possible, because attributes are far simpler. All attributes of an element effectively constitute an unordered set of named simple values. There is no some kind of attribute tree (with the variable structure at that) attached to the parent element.

    But with elements things are far more complex. If something "default" about missing elements were allowed, that would cause lots of ambiguities. For instance, some kind of "default content" would have to be specified then, which would be some sequence of elements evoked automatically in place of emptiness... or even a number of possible "default contents" each evoked when only some elements are specified explicitly and others must supplement them implicitly (by default). .... Well, if you think further on, the things are getting mind-boggling complex. Another language would have to be created then! But for what purpose?

    0 讨论(0)
提交回复
热议问题