Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML schema check error

Tags:

xml

schema

I am using the following schema to check the following XML file. And I find when there is more than one Information elements inside People elements, the schema check will fail. Why and how to fix it (I want to allow People element to be able to nest more than one Information items)?

XML Schema file:

  <xs:element name="People">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Information">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="Name" type="xs:string"/>
            </xs:sequence>
            <xs:attribute name="Id" type="xs:string"/>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

XML file (schema check will fail):

  <People>
    <Information Id="1">
      <Name>John</Name>
    </Information>
    <Information Id="2">
      <Name>Mike</Name>
    </Information>
  </People>

XML file (schema check will success):

  <People>
    <Information Id="1">
      <Name>John</Name>
    </Information>
  </People>

thanks in advance, George

like image 226
George2 Avatar asked Dec 28 '25 11:12

George2


1 Answers

If you dont specify minOccurs and maxOccurs with the sequence, the default value is 1.

<xs:element name="Information" minOccurs = "1" maxOccurs = "unbounded">
like image 179
Mork0075 Avatar answered Dec 31 '25 13:12

Mork0075