Element-Mandatory Attribute declaration in XSD Schema:

后端 未结 4 1567
故里飘歌
故里飘歌 2021-02-19 15:46

I want to declare an element to be included in a complex type declaration, and the element has a mandatory attribute: \"option=MyOption\", but the value of the \"option\

4条回答
  •  遇见更好的自我
    2021-02-19 16:53

    To mark an attribute as mandatory you use .

    As for type, you have a choice of the built-in XSD types (xs:string etc), or you can define your own and use that.

    UPDATE

    I am not certain what you mean by the attribute must have a value that is not yet known. Does this mean that the value is a string, but can be any string? Or a decimal?

    Because it's an attribute value we are talking about you are restricted to using the built-in XSD types, or defining your own xs:simpleType type based on one of the built-in types. This is where you can apply more stringent rules to the allowed value, for example by extending xs:string and adding a regular expression constraint to allowed values.

    
        
            
        
    
    

    However, if there is absolutely no way of knowing what value will be used then you have the well known temporal paradox whereby you cannot restrict something at design-time to a value you only know at run-time. In this instance, surely it is only necessary to specify that the attribute must at least be present?

    Hope this answers your question a little more clearly.

提交回复
热议问题