如何在 XML Schema 1.1 中使用替代方案 [英] How to use alternatives in XML Schema 1.1
本文介绍了如何在 XML Schema 1.1 中使用替代方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从我读过的所有内容来看,我在下面定义的模式应该可以工作(强调替代方案).我收到以下错误:'http://www.w3.org/2001/XMLSchema:alternative' 元素在此上下文中不受支持.
From everything I have read, the schema I have defined below should work (emphasis on alternatives). I get the following error: The 'http://www.w3.org/2001/XMLSchema:alternative' element is not supported in this context.
你能指出我做错了什么吗?
Could you please point out what I did wrong?
这是我当前的架构:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd"
elementFormDefault="qualified"
xmlns="http://tempuri.org/XMLSchema.xsd"
xmlns:mstns="http://tempuri.org/XMLSchema.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="object">
<xs:complexType>
<xs:choice maxOccurs="unbounded" minOccurs="0">
<xs:element name="property" type="xs:string">
<xs:alternative test="@name='VIN'" type="VinType"/>
<xs:alternative test="@name='Year'" type="YearType"/>
<xs:alternative test="@name='Make'" type="MakeType"/>
</xs:element>
</xs:choice>
<xs:attribute name="type" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
<!-- Vehicle Identification number (VIN) -->
<xs:simpleType name="VinRestriction">
<xs:restriction base="xs:string">
<xs:length fixed="true" value="17"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="VinType" mixed="true">
<xs:simpleContent>
<xs:extension base="VinRestriction">
<xs:attribute name="name" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="VIN" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<!-- Vehicle Year -->
<xs:simpleType name="YearRestriction">
<xs:restriction base="xs:gYear"/>
</xs:simpleType>
<xs:complexType name="YearType" mixed="true">
<xs:simpleContent>
<xs:extension base="YearRestriction">
<xs:attribute name="name" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="Year" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<!-- Vehicle Make -->
<xs:simpleType name="MakeRestriction">
<xs:restriction base="xs:string">
<xs:enumeration value="Chevrolet"/>
<xs:enumeration value="Ford"/>
<xs:enumeration value="Mazda"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="MakeType" mixed="true">
<xs:simpleContent>
<xs:extension base="MakeRestriction">
<xs:attribute name="name" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="Make" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:schema>
推荐答案
很可能您正在使用不支持 XSD 1.1 的架构处理器.
Most likely you are using a schema processor that doesn't support XSD 1.1.
这篇关于如何在 XML Schema 1.1 中使用替代方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文