How to indicate that an xml schema that requires schema 1.1 features?

試著忘記壹切 提交于 2019-11-30 12:37:41

At this point in time, this issue is not that easy to resolve; this is because most of the XSD processors are 1.0, and the schema versioning introduced in XSD 1.1 spec can't apply backwards. To learn more about it (in general) have a look at The Schema Versioning Namepsace, and the examples included in section 4.2.2 Conditional inclusion.

You could implement your own pre-processing solution, that is to at least help with choosing the appropriate XSD processor using something such as this:

<?xml version="1.0" encoding="utf-8" ?>
<!-- XML Schema generated by QTAssistant/XSD Module (http://www.paschidev.com) -->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning">

    <xsd:element name="e" vc:minVersion="1.1">
        <xsd:complexType>
            <xsd:all>
                <xsd:element name="a" minOccurs="0"/>
                <xsd:element name="b" maxOccurs="unbounded"/>       
            </xsd:all>
        </xsd:complexType>
    </xsd:element>
    <xsd:element name="e" vc:minVersion="1.0" vc:maxVersion="1.1">
        <xsd:complexType>
            <xsd:choice maxOccurs="unbounded">
                <xsd:element name="a" minOccurs="0"/>
                <xsd:element name="b" />            
            </xsd:choice>
        </xsd:complexType>
    </xsd:element>      
</xsd:schema>

This way at least you'll be using an XSD 1.1 endorsed approach to versioning; it also comes with a processing model. For certain tasks, it is relatively easy to build a pre-processor that at least will handle the appropriate selection of the XSD processor (1.0 or 1.1) . To make simpler in a closed environment, you could also choose a convention where you could mark the whole xsd:schema with vc:minVersion="1.1" - basically what you seem to have wanted to begin with.

Regarding your last paragraph, the choice of the XSD processor has to be asserted rather than implied. This is because XSD 1.1 allows for constructs that were impossible in XSD 1.0 (e.g. an all compositor containing particles with max occurrence greater than 1)... so unless one makes a prior decision re: the processor to use, the XSD may or may not be invalid. Whereas other things will be invalid regardless of the processor used.

There was a discussion related to this on the XML Schema dev list: http://lists.w3.org/Archives/Public/xmlschema-dev/2013Sep/0000.html

And the conclusion was that we should use the vc:minVersion and vc:maxVersion attributes on the xsd:schema element if we want to specify the version of the XML Schema. The attributes are not in the schema namespace, they are in the "http://www.w3.org/2007/XMLSchema-versioning" namespace. So, you can set them also on an XML Schema version 1.0, and this schema will be valid.

So, if you want to specify if a schema is version 1.0, you can set the version attributes on the xsd:schema element like this: vc:minVersion="1.0" vc:maxVersion="1.1" (minVersion is inclusive, maxVersion is exclusive).

If you want to set the schema version to 1.1, you can set the version attributes on the xsd:schema element like this: vc:minVersion="1.1". The maxVersion attribute doesn't need to be set in this case because we don't have yet XML Schema versions grater that 1.1.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!