2012-06-22 16 views
7

xmlとxsdファイルの両方が正しく検証されています(でテスト済み)。

ただし、xmlはxsdに対して検証されません。これは、xmlと比べて、xsdのcomplexType要素を間違って入れ子にしているためです。 peopleの外側の要素が問題を引き起こしているようだ...ここ

はXMLです:
どのようにxsdのcomplexType要素をネストしますか?

<?xml version = "1.0"?> 

<people> 
    <person> 
     <firstname>Joe</firstname> 
     <lastname>Schmoe</lastname> 
    </person> 

    <person> 
     <firstname>Cletus</firstname> 
     <lastname>Jenkins</lastname> 
    </person> 
</people> 

...と、ここでのxsdです:

<?xml version = "1.0"?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 

    <xs:element name = "people"> 
     <xs:complexType> 
      <xs:sequence> 

       <xs:element name = "person"> 
        <xs:complexType> 
         <xs:sequence> 

          <xs:element name = "firstname" type = "xs:string" /> 
          <xs:element name = "lastname" type = "xs:string" /> 

         </xs:sequence> 
        </xs:complexType> 
       </xs:element> 

      </xs:sequence> 
     </xs:complexType> 
    </xs:element> 

</xs:schema> 

答えて

10

"person"という要素にmaxoccurs="unbounded"を追加します。これは、1つまたは複数の人物要素のシーケンスです。

+0

ねえ、あなたは正しい、それは、そのためのおかげでシンプルなソリューションです、 –

+0

ああ:-)私の答えを無視! –

2

があなたのXSDのためにこれを試してみてください:

<?xml version = "1.0"?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 

    <xs:element name="people" type="people"/> 

    <xs:complexType name="people"> 
     <xs:sequence> 
      <xs:element name="person" type="person" maxOccurs="unbounded" minOccurs="0"/> 
     </xs:sequence> 
    </xs:complexType> 

    <xs:complexType name="person"> 
     <xs:sequence> 
      <xs:element name="firstname" type="xs:string" maxOccurs="1" minOccurs="1"/> 
      <xs:element name="lastname" type="xs:string" maxOccurs="1" minOccurs="1"/> 
     </xs:sequence> 
    </xs:complexType> 

</xs:schema> 
+0

Btw、いくつかの要素の出現回数に制限をいくつか追加しましたが、これらは必要に応じて変更または省略できます。 –

+0

これは興味深い解決策です@JonoB ...これは、 ... 'tags? –

関連する問題