実際<xs:element name="person" maxOccurs="1">
には不要であり、十分で<xs:element name="person">
あるべきです。
<xs:choice maxOccurs="unbounded">
2人がOKと評価されたのはそのためです。試してみてください<xs:choice>
。
maxOccurs<xs:element name="address" type="xs:string" minOccurs="1"/>
属性を追加する必要があります<xs:element name="address" type="xs:string" minOccurs="1" maxOccurs="unbounded" />
編集:
次のようなものを作成できます。
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="family">
<xs:complexType>
<!-- Choice between one "person" element and one or more "address" element. They cannot occur simultaneously because of choice -->
<xs:choice>
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="age" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="address" type="xs:string" minOccurs="1" maxOccurs="unbounded"/>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
この場合、1 人の xml が検証されます
<?xml version="1.0" encoding="UTF-8"?>
<family xsi:noNamespaceSchemaLocation="Untitled4.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<person>
<name>String</name>
<firstname>String</firstname>
<age>0</age>
</person>
</family>
または多くのアドレス要素を含むxmlが検証されます
<?xml version="1.0" encoding="UTF-8"?>
<family xsi:noNamespaceSchemaLocation="Untitled4.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<address>a</address>
<address>b</address>
<address>c</address>
</family>
2 人の人物を含む XML は、1 人の人物といくつかの住所要素を含む XML と同様に検証されません (選択構造のため)。
1 つの XML に person 要素と address 要素の両方が必要な場合は、次のように選択をシーケンスに変更する必要があります。
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="family">
<xs:complexType>
<xs:sequence>
<!-- Only 0 or 1 "person element might appear -->
<xs:element name="person" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="age" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<!-- followed by many "address" elements -->
<xs:element name="address" type="xs:string" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
たとえば、次のxmlは検証されます
<?xml version="1.0" encoding="UTF-8"?>
<family xsi:noNamespaceSchemaLocation="Untitled4.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<person>
<name>String</name>
<firstname>String</firstname>
<age>0</age>
</person>
<address>String</address>
<address>String</address>
<address>String</address>
</family>
としても
<?xml version="1.0" encoding="UTF-8"?>
<family xsi:noNamespaceSchemaLocation="Untitled4.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<address>String</address>
<address>String</address>
<address>String</address>
</family>
前の例では、「person」要素は 0 または 1 つしか存在できず、シーケンスがこの順序を強制するため、すべての要素の最初になければなりませんでした。
address 要素が person 要素の前に必要な場合は、モデルを all に変更する必要があります。残念ながら、このモデルでは、1 つの要素をこれ以上出現させることはできないため、次のようにアドレス要素を別の要素に「ラップ」する必要があります。
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="family">
<xs:complexType>
<xs:all>
<!-- Only 0 or 1 "person element might appear -->
<xs:element name="person" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="age" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<!-- or many "address" elements packed into "addresses" element-->
<xs:element name="addresses">
<xs:complexType>
<xs:sequence>
<xs:element name="address" type="xs:string" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
この場合、次の XML が検証されます
例 1
<?xml version="1.0" encoding="UTF-8"?>
<family xsi:noNamespaceSchemaLocation="Untitled4.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<person>
<name>String</name>
<firstname>String</firstname>
<age>0</age>
</person>
<addresses>
<address>String</address>
<address>String</address>
<address>String</address>
</addresses>
</family>
例 2
<?xml version="1.0" encoding="UTF-8"?>
<family xsi:noNamespaceSchemaLocation="Untitled4.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<addresses>
<address>String</address>
<address>String</address>
<address>String</address>
</addresses>
<person>
<name>String</name>
<firstname>String</firstname>
<age>0</age>
</person>
</family>
例 3
<?xml version="1.0" encoding="UTF-8"?>
<family xsi:noNamespaceSchemaLocation="Untitled4.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<addresses>
<address>String</address>
<address>String</address>
<address>String</address>
</addresses>
</family>