我正在上学 这是我的 XML lineup xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ComplexTypeDemo.xsd" team teamName="Maple Leafs" city="Toronto" visitor/ player number="17" nameJohn Doe/name posit
这是我的 XML
<lineup xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ComplexTypeDemo.xsd"> <team teamName="Maple Leafs" city="Toronto"> <visitor/> <player number="17"> <name>John Doe</name> <position>Forward</position> </player> <!--Continue 20 Iterations--> </team> <team teamName="Rangers" city="New York"> <home/> <player number="17"> <name>John Doe</name> <position>Forward</position> </player> <!--Continue 20 Iterations--> </team> </lineup>
这是我的架构文档
<?xml version="1.0" encoding="utf-8"?> <xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="lineup"> <xs:complexType> <xs:sequence> <xs:element name="team" minOccurs="2" maxOccurs="2"> <xs:complexType> <xs:sequence> <xs:choice> <xs:element name="home"/> <xs:element name="visitor"/> </xs:choice> <xs:element name="player" minOccurs="20" maxOccurs="20"> <xs:complexType> <xs:all> <xs:element name="name" /> <xs:element name="position"/> </xs:all> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
我需要制作一个模式来验证这一点.但我无法弄清楚如何验证,因为它是嵌套但它有属性.我似乎只能做一个或另一个,但不是两个….
你很亲密您可以在xs:sequence或xs:all close标记之后但在xs:complexType close标记之前放置属性声明.对XSD的此更新将验证您提供的XML文档实例(模数实际上包括20个迭代,如上所述):<?xml version="1.0" encoding="utf-8"?> <xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="lineup"> <xs:complexType> <xs:sequence> <xs:element name="team" minOccurs="2" maxOccurs="2"> <xs:complexType> <xs:sequence> <xs:choice> <xs:element name="home"/> <xs:element name="visitor"/> </xs:choice> <xs:element name="player" minOccurs="20" maxOccurs="20"> <xs:complexType> <xs:all> <xs:element name="name" /> <xs:element name="position"/> </xs:all> <xs:attribute name="number" type="xs:integer"/> </xs:complexType> </xs:element> </xs:sequence> <xs:attribute name="teamName"/> <xs:attribute name="city"/> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>