How to define xsi:type as an attribute in XML-schema?

后端 未结 2 1056
滥情空心
滥情空心 2021-01-17 18:00

I have an XML for which I want to write a schema definition. The problem is that I don\'t know how to define xsi:type as an attribute. Here is the XML element:



        
2条回答
  •  再見小時候
    2021-01-17 18:27

    You don't need to - just declare the element without a type at all.

    
    

    The xsi:type attribute is used to indicate to the schema validator that the real type of a particular instance of an element is not the element's declared type but rather a sub-type derived from the declared type. By declaring the element with no type you are saying it can have any type, and you will use xsi:type in the instance to specify which.

    Strictly you're declaring an element whose type is the "ur-type" which is the root of the XML Schema type hierarchy - all types, simple and complex, ultimately derive from the ur-type. If you want to restrict the SerializedData element to simple content only (no sub-elements or attributes) then declare it as

    
    

    Regarding the second part of your question, your designer tool is right that in isolation

    300.0
    

    is not correct XML, because the xsi namespace has not been declared. Try adding the namespace declarations:

    300.0
    

提交回复
热议问题