无法获得 XSD 1.1 类型的替代工作



我正在尝试在XSD 1.1中编写XML模式文档。具体来说,我正在尝试使用类型的替代方案。

我的XSD文档如下

<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified"
           targetNamespace="http://shop.accesso.com"
           xmlns="http://shop.accesso.com"
           xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="CONFIG">
        <xs:complexType>
            <xs:sequence>
                <!-- define an element named 'settings' -->
                <xs:element name="settings">
                    <xs:complexType>
                        <xs:attribute name="servlet" type="xs:anyURI" use="required"/>
                        <xs:attribute name="machineId" type="xs:unsignedByte" use="required"/>
                        <xs:attribute name="merchantId" type="xs:unsignedShort" use="required"/>
                        <xs:attribute name="language" type="xs:string"/>
                        <xs:attribute name="locale" type="xs:string"/>
                        <xs:attribute name="maximize" type="xs:boolean"/>
                    </xs:complexType>
                </xs:element>
                <!-- any number of PARAM elements, setting alternative types based on the key attribute value -->
                <xs:element name="PARAM" type="baseParamType" maxOccurs="unbounded">
                    <xs:alternative test="@key='printers'" type="printerParamType"/>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <!-- base PARAM type -->
    <xs:complexType name="baseParamType">
        <xs:attribute name="key" use="required" type="paramKeyTypes"/>
    </xs:complexType>
    <!-- Printer PARAM type -->
    <xs:complexType name="printerParamType">
        <xs:complexContent>
            <!-- extend the base PARAM type -->
            <xs:extension base="baseParamType">
                <!-- the printer PARAM can have a child FORMAT element -->
                <xs:sequence>
                    <xs:element name="FORMAT">
                        <xs:complexType>
                            <xs:attribute name="name" use="required" type="xs:string"/>
                            <xs:attribute name="printer" use="required" type="xs:string"/>
                        </xs:complexType>
                    </xs:element>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    <!-- Normal PARAM -->
    <xs:complexType name="nonPrinterParamType">
        <!-- empty for now -->
    </xs:complexType>
    <!-- valid values for the key attribute of PARAM elements -->
    <xs:simpleType name="paramKeyTypes">
        <xs:restriction base="xs:string">
            <xs:enumeration value="printers"/>
            <xs:enumeration value="dynamic_gateway_config"/>
        </xs:restriction>
    </xs:simpleType>
</xs:schema>

这是它正在验证的配置

<?xml version="1.0"?>
<CONFIG xmlns="http://shop.accesso.com"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://shop.accesso.com config.xsd">
    <settings servlet="http://localhost:1813"
              machineId="1"
              merchantId="803"
              language="en"
              locale="en_US"
              maximize="false" />
    <PARAM key="printers">
      <FORMAT name="default" printer="Microsoft XPS Document Writer" />
    </PARAM>
    <PARAM key="use_static_gateway_config" />
</CONFIG>

但是,使用"打印机"的键说

的键是错误的。

元素格式在此处不允许

这就是我对撒克逊人得到的:

Schema checking successful. Time: 1784ms. Memory: 53Mb.
Using parser org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser
Processing file:/Users/mike/Desktop/temp/test.xml
Validation error on line 17 column 46 of test.xml:
  FORG0001: Value "use_static_gateway_config" contravenes the enumeration facet "printers,
  dynamic_gateway_conf..." of the type Q{http://shop.accesso.com}paramKeyTypes
  See http://www.w3.org/TR/xmlschema-2/#cvc-complex-type clause 3

如果我将" use_static_gateway_config"添加到枚举中,一切正常。

因此,我的结论是您的模式和实例文档基本上是可以的(要通过此更正),并且您的XSD处理器或调用它的方式存在问题。

最新更新