刚写了这样一个XML,始终不是valid。
捣鼓半天,把所有的xs:加上了,结果还真通过了,这个是什么原因呢?
报错信息是 '学生' must refer to an existing element.
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<element name="姓名" type="string"/>
<element name="性别">
<simpleType>
<restriction base="string">
<pattern value="(男|女)"/>
</restriction>
</simpleType>
</element>
<element name="年龄">
<simpleType>
<restriction base="integer">
<minExclusive value="0"/>
<maxExclusive value="150"/>
</restriction>
</simpleType>
</element>
<attribute name="学号" type="integer"/>
<complexType name="stu">
<sequence maxOccurs="1">
<element ref="姓名"/>
<element ref="性别"/>
<element ref="年龄"/>
</sequence>
<attribute ref="学号" use="required"/>
</complexType>
<element name="学生" type="stu"/>
<complexType name="myT">
<sequence>
<element ref="学生" maxOccurs="unbounded"/>
</sequence>
</complexType>
<element name="学生名册" type="myT"/>
这个是后来加上的,没问题
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="学生名册" type="myT"/>
<xs:complexType name="myT">
<xs:sequence maxOccurs="unbounded">
<xs:element ref="学生"/>
</xs:sequence>
</xs:complexType>
<xs:element name="学生" type="stu"/>
<xs:element name="姓名" type="xs:string"/>
<xs:element name="性别">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="(男|女)"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="年龄">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
<xs:maxExclusive value="150"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:attribute name="学号" type="xs:integer"/>
<xs:complexType name="stu">
<xs:sequence maxOccurs="1">
<xs:element ref="姓名"/>
<xs:element ref="性别"/>
<xs:element ref="年龄"/>
</xs:sequence>
<xs:attribute ref="学号" use="required"/>
</xs:complexType>
</xs:schema>