由于来自xsd的xs:alternative
,我的xml不匹配。
XML代码
<?xml version="1.0" encoding="UTF-8"?>
<install xmlns="h4a:install" xmlns:h4a="https://www.hive-4-apps.org/xml-shemas/install.xsd" >
<database>
<tables>
<table name="foo">
<column name="foo_id" type="bigint(20)" />
<column name="foo_name" type="varchar(255)" />
<column name="foo_type" type="varchar(35)" />
<column name="foo_type_id" type="int(40)"/>
<key type="unique">
<column ref="foo_name"/>
<column ref="foo_type"/>
</key>
<key type="index" name="foo_type_id" col_name="form_type_id" />
</table>
</tables>
</database>
</install>
XSD代码
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema elementFormDefault="qualified" targetNamespace="h4a:install" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="install" type="h4a:installType" xmlns:h4a="h4a:install"/>
<xs:complexType name="installType">
<xs:sequence>
<xs:element type="databaseType" name="database"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="columnType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="name" use="required"/>
<xs:attribute type="xs:string" name="type" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="columnKeyType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="ref" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="tableType">
<xs:sequence>
<xs:element type="columnType" name="column" maxOccurs="unbounded" minOccurs="0"/>
<xs:element type="keyType" name="key" maxOccurs="unbounded" minOccurs="0">
<xs:alternative type="keyIndexType" test="@type='index'"/>
<xs:alternative test="@type='unique'" type="KeyUniqueType"/>
</xs:element>
</xs:sequence>
<xs:attribute type="xs:string" name="name" use="required"/>
</xs:complexType>
<xs:complexType name="tablesType">
<xs:sequence>
<xs:element type="tableType" name="table" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="databaseType">
<xs:sequence>
<xs:element type="tablesType" name="tables" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="keyType">
<xs:attribute name="type" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="index|unique"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
<xs:complexType name="keyIndexType">
<xs:simpleContent>
<xs:extension base="keyType">
<xs:attribute type="xs:string" name="name" use="required"/>
<xs:attribute type="xs:string" name="col_name" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="KeyUniqueType">
<xs:complexContent>
<xs:extension base="keyType">
<xs:sequence>
<xs:element type="columnKeyType" name="column" maxOccurs="unbounded"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
我尝试了几种可能性而没有成功。我的xsd有什么问题?