I want to do the validations like:
<A>
<B> or <C>
<D>
</A>
In the , the first element should be one of the B and C. The second element is D. And at the same time, the first element B or C and the second element do not in sequence. It could become and . Anybody know how to do it?
To match your example, please try:
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="A">
<xs:complexType>
<xs:sequence>
<xs:choice>
<xs:element name="B" type="xs:string"/>
<xs:element name="C" type="xs:string"/>
</xs:choice>
<xs:element name="D" type="xs:string" minOccurs="0" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
You have to use two things here, the first one is <xs:choice> which allows only one elements to be present in xml.
In order to make an element optional (D) you have to specify minOccurs="0".
Edited (after feedback): All valid cases are covered with this XSD.
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="B" type="xs:string"/>
<xs:element name="C" type="xs:string"/>
<xs:element name="D" type="xs:string"/>
<xs:complexType name="OurType">
<xs:choice>
<xs:sequence>
<xs:element ref="D"/>
<xs:choice>
<xs:element ref="B"/>
<xs:element ref="C"/>
</xs:choice>
</xs:sequence>
<xs:sequence>
<xs:choice>
<xs:element ref="B"/>
<xs:element ref="C"/>
</xs:choice>
<xs:element ref="D"/>
</xs:sequence>
</xs:choice>
</xs:complexType>
<xs:element name="A" type="OurType"/>
</xs:schema>
I get the best practice. It should be as below:
<xs:element name="A">
<xs:complexType>
<xs:all>
<xs:element ref="Choice" minOccurs="1" maxOccurs="1"/>
<xs:element ref="D" minOccurs="0" maxOccurs="1"/>
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="D" type="xs:string"/>
<xs:element name="Choice" abstract="true"/>
<xs:element name="B" substitutionGroup="Choice">
</xs:element>
<xs:element name="C" substitutionGroup="Choice">
</xs:element>
Related
I am trying to map XSD to another XSD that has some different elements in Smooks. When I add both XSDs in Smooks it is not allowing me to map the elements. Is it possible in Smooks to map two different XSDs?
XSD1:CDM
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:RequestResponse="http://example.com/cdm/xsd/Person_01_RequestResponse_001"
xmlns:prsn="http:/example.com/cdm/xsd/Person_01"
attributeFormDefault="unqualified" elementFormDefault="qualified"
targetNamespace="http://example.com/cdm/xsd/Person_01_RequestResponse_001">
<!-- ************ import Employee Model ************ -->
<xs:import namespace="http://example.com/cdm/xsd/Person_01" schemaLocation="Person_01.xsd"/>
<!-- ********************************************* -->
<!-- Request Response Types -->
<!-- ********************************************* -->
<!-- For CreatePerson operation-->
<xs:element name="CreatePersonRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="PersonDetail" type="prsn:Person"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="CreatePersonResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="ResponseCode" type="xs:string"/>
<xs:element name="ResponseMessage" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<!-- For GetPerson operation-->
<xs:element name="GetPersonRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="PersonId" type="prsn:PersonIdType" nillable="false"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetPersonResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="Person" type="prsn:Person" minOccurs="0" nillable="true"/>
<xs:element name="ResponseCode" type="xs:string"/>
<xs:element name="ResponseMessage" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
XSD2:LEGACY
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:RequestResponse="http://example.com/xsd/Person_01_RequestResponse_001"
xmlns:prsn="http://example.com/xsd/Person_01"
attributeFormDefault="unqualified" elementFormDefault="qualified"
targetNamespace="http://example.com/xsd/Person_01_RequestResponse_001">
<!-- ************ import Employee Model ************ -->
<xs:import namespace="http://example.com/xsd/Person_01" schemaLocation="Person_01.xsd"/>
<!-- ********************************************* -->
<!-- Request Response Types -->
<!-- ********************************************* -->
<!-- For CreatePerson operation-->
<xs:element name="CreatePersonRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="PersonDetail" type="prsn:Person"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="CreatePersonResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="ResponseCode" type="xs:string"/>
<xs:element name="ResponseMessage" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<!-- For GetPerson operation-->
<xs:element name="GetPersonRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="CNIC" type="xs:string" nillable="false" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetPersonResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="Person" type="prsn:Person" minOccurs="0" nillable="true"/>
<xs:element name="ResponseCode" type="xs:string"/>
<xs:element name="ResponseMessage" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<!-- For UpdatePerson operation-->
<xs:element name="UpdatePersonRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="Person" type="prsn:Person"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="UpdatePersonResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="ResponseCode" type="xs:string"/>
<xs:element name="ResponseMessage" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<!-- For deletePerson operation-->
<xs:element name="DeletePersonRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="CNIC" type="xs:string" nillable="false" minOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="DeletePersonResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="ResponseCode" type="xs:string"/>
<xs:element name="ResponseMessage" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Hi again SO community,
got another request regarding how to define an XSD schema correctly.
Given I have an XML file like:
<?xml version="1.0" encoding="UTF-8" ?>
<transformation xmlns="http://www.denktmit.de/pdi/ktr" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://www.w3.org/2001/XMLSchema-instance
./test.xsd">
<info>
<name>TrafoName</name>
<description>TrafoDescription</description>
</info>
<changedby>LastUser</changedby>
<step>
<type>FileInput</type>
<description>FileInput Step description</description>
<FileInputParameterOne>FileInputParam</FileInputParameterOne>
<another>1</another>
</step>
<step>
<type>Select</type>
<description>Select Step description</description>
<SelectParameterOne>SelectParameterOne</SelectParameterOne>
<SelectParameterTwo>SelectParameterTwo</SelectParameterTwo>
<another>2</another>
</step>
</transformation>
This resembles the style of the transformation files as produced by http://community.pentaho.com/projects/data-integration/
As you can see, each step contains several sequence nodes on top
<type>Select</type>
<description>Select Step description</description>
and on bottom:
<another>2</another>
In between, arbitrary complex xml subtrees may occur. But what exactely max occur is determined by the value in "type". The use case is to store specific configurations for concrete Java classes, that all implement an interface, defining getters/setter for "type", "description" and "another" and defining addtional object structure themself. It would also be sufficient to neglect the order, as long as all the elements, needed for a specific class are somehow present.
I already read:
How to group types & subtypes in XSD
xsd: How to extend a type with an unordered list of elements
Use <xs:all> in XML schema's complexType?
xsd: How to extend a type with an unordered list of elements
And I tried something like
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.denktmit.de/pdi/ktr" elementFormDefault="qualified"
attributeFormDefault="unqualified" xmlns="http://www.denktmit.de/pdi/ktr">
<xs:element name="transformation">
<xs:complexType>
<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="step" type="fileInputStep"></xs:element>
<xs:element name="step" type="selectStep"></xs:element>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="stepComplexType" abstract="true"></xs:complexType>
<xs:complexType name="fileInputStep">
<xs:complexContent>
<xs:extension base="stepComplexType">
<xs:sequence>
<xs:element name="type" minOccurs="1"
maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string"></xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="description" type="xs:string"
minOccurs="1" maxOccurs="1"></xs:element>
<xs:element name="FileInputParameterOne" type="xs:string">
</xs:element>
<xs:element name="another" type="xs:int" minOccurs="1"
maxOccurs="1"></xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="selectStep">
<xs:complexContent>
<xs:extension base="stepComplexType">
<xs:sequence>
<xs:element name="type" minOccurs="1"
maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="Select"></xs:pattern>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="description" type="xs:string"
minOccurs="1" maxOccurs="1"></xs:element>
<xs:element minOccurs="1" name="SelectParameterOne"
type="xs:string">
</xs:element>
<xs:element minOccurs="1" name="SelectParameterTwo"
type="xs:string">
</xs:element>
<xs:element name="another" type="xs:int" minOccurs="1"
maxOccurs="1"></xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
But it is not working, telling me:
Multiple annotations found at this line: validation against this
schema, ambiguity would be created for those two particles.
- Start tag of element
- cos-element-consistent: Error for type '#AnonType_transformation'. Multiple elements with name 'step', with different types, appear in
the model group.
Any ideas?
You may use xsd Group. Here's an sample for your reference
XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="transformation">
<xs:complexType>
<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="step" type="stepType"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="stepComplexType" abstract="true"></xs:complexType>
<xs:group name="selectParamGroup">
<xs:sequence>
<xs:element name="SelectParameterOne" type="xs:string" minOccurs="1" maxOccurs="1">
</xs:element>
<xs:element name="SelectParameterTwo" type="xs:string" minOccurs="1" maxOccurs="1">
</xs:element>
</xs:sequence>
</xs:group>
<xs:group name="paramGroup">
<xs:choice>
<xs:element name="FileInputParameterOne" type="xs:string">
</xs:element>
<xs:group ref="selectParamGroup">
</xs:group>
</xs:choice>
</xs:group>
<xs:complexType name="stepType">
<xs:complexContent>
<xs:extension base="stepComplexType">
<xs:sequence>
<xs:element name="type" minOccurs="1"
maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string"></xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="description" type="xs:string"
minOccurs="1" maxOccurs="1"></xs:element>
<xs:group ref="paramGroup"></xs:group>
<xs:element name="another" type="xs:int" minOccurs="1"
maxOccurs="1"></xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
XML:
<?xml version="1.0" encoding="UTF-8" ?>
<transformation>
<step>
<type>FileInput</type>
<description>FileInput Step description</description>
<FileInputParameterOne>FileInputParam</FileInputParameterOne>
<another>1</another>
</step>
<step>
<type>Select</type>
<description>Select Step description</description>
<SelectParameterOne>SelectParameterOne</SelectParameterOne>
<SelectParameterTwo>SelectParameterTwo</SelectParameterTwo>
<another>2</another>
</step>
</transformation>
In XMLSpy, there is a validation error, "Value '18' is not allowed for attribute 'name'. Hint: A valid value would be 'NCName'. Error location: xs:schema / xs:element / xs:complexType / xs:choice / xs:element / xs:complexType / xs:choice / xs:element / #name" here:
<xs:element name="Age">
<xs:complexType>
<xs:choice>
<xs:element name="18" type="xs:int"/>
If I enter letters it validates, but I need numbers in that field.
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="http://www.urent.com/Elmhurst" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.urent.com/Elmhurst" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="URent">
<xs:annotation>
</xs:annotation>
<xs:complexType>
<xs:choice>
<xs:element name="RentalPeriod">
<xs:complexType>
<xs:all>
<xs:element name="StartDate" type="xs:date"/>
<xs:element name="EndDate" type="xs:date"/>
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="Age">
<xs:complexType>
<xs:choice>
<xs:element name="18" type="xs:int"/>
<xs:element name="19" type="xs:int"/>
<xs:element name="20" type="xs:int"/>
<xs:element name="21" type="xs:int"/>
<xs:element name="22" type="xs:int"/>
<xs:element name="23" type="xs:int"/>
<xs:element name="24" type="xs:int"/>
<xs:element name="25+" type="xs:int"/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="RateCode">
<xs:complexType>
<xs:choice>
<xs:element name="Corporate" type="xs:string"/>
<xs:element name="Leisure" type="xs:string"/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="TypeOfVehicle">
<xs:complexType>
<xs:all>
<xs:element name="Subcompact" type="xs:string"/>
<xs:element name="Compact" type="xs:string"/>
<xs:element name="Intermediate" type="xs:string"/>
<xs:element name="Standard" type="xs:string"/>
<xs:element name="Full Size" type="xs:string"/>
<xs:element name="Premium" type="xs:string"/>
<xs:element name="Luxury" type="xs:string"/>
<xs:element name="Standard Elite SUV" type="xs:string"/>
<xs:element name="Intermediate SUV" type="xs:string"/>
<xs:element name="Minivan" type="xs:string"/>
<xs:element name="Full Size SUV" type="xs:string"/>
<xs:element name="Standard SUV" type="xs:string"/>
<xs:element name="Premium SUV" type="xs:string"/>
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="Residence">
<xs:complexType>
<xs:choice>
<xs:element name="US" type="xs:string"/>
<xs:element name="OutsideUS" type="xs:string"/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="SpecialEquipment">
<xs:complexType>
<xs:choice>
<xs:element name="GPS Navigation" type="xs:string"/>
<xs:element name="XM Radio" type="xs:string"/>
<xs:element name="Fuel Service" type="xs:string"/>
<xs:element name="Child Safety Seats" type="xs:string"/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="Customer Info">
<xs:complexType>
<xs:sequence>
<xs:element name="FirstName" type="xs:string"/>
<xs:element name="LastName" type="xs:string"/>
<xs:element name="EmailAddress" type="xs:string"/>
<xs:element name="PhoneNumber" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
Taken literally, your declaration says the set of valid Age elements includes <Age><18>45</18></Age> and <Age><25+>33</25+></Age>, though not <Age><45>18</45></Age>.
But '18' and '25+' are not allowed by XML as names of element types; like names of variables in most programming languages, names of element types in XML must begin with a letter. (They are also not allowed to contain blanks, so the element names "Full Size" and "Standard Elite SUV" will also raise errors.) So the examples given in the preceding paragraph are not XML, and you cannot define an XSD schema against which they would be valid.
It's not clear whether you need to review the basics of XML or the basics of XSD, but your work developing a schema will be more pleasant and productive if you have a better grasp of the technologies you are trying to use; that helps you work with the grain of the technology and not against it.
Below is the sample xml which has multiple <rulex> that starts with sequence 1 and it can end up to many rule like <rule1> , <rule2>, <rule3> etc....
<?xml version="1.0" encoding="UTF-8"?>
<AddressChange_181>
<rules>
<rule1>
<conditions>xya</conditions>
<response_path>abc</response_path>
</rule1>
<rule2>
<conditions>xxxx</conditions>
<response_path>aaaa</response_path>
</rule2>
<rule3>
<conditions>yyyyy</conditions>
<response_path>ffff</response_path>
</rule3>
<rule4>
<conditions>zzzz</conditions>
<response_path>yyyy</response_path>
</rule4>
<default>
<response_path>uuuuu</response_path>
</default>
</rules>
</AddressChange_181>
Below is the schema where i tried creating dynamic <rulex> element name for the above xml.
when i generate xml from this schema i do not get the same xml format as above xml.
can you please let me know how to create schema with multiple element name that starts with a sequence number.
My requirement is to add more than one rule (<rule1>,<rule2>,<rule3> etc...) in xml file and this xml file should be validated against schema.
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="mock_rule_list">
<xs:complexType>
<xs:sequence>
<xs:element ref="rules" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="rules">
<xs:complexType>
<xs:sequence>
<xs:element ref="rule" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="default" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="rule">
<xs:complexType>
<xs:simpleContent>
<xs:restriction base="xs:anyType">
<xs:pattern value="rule/d{1,3}"></xs:pattern>
</xs:restriction>
</xs:simpleContent>
<xs:sequence>
<xs:element ref="conditions" minOccurs="1" maxOccurs="1"/>
<xs:element ref="response_path" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="default">
<xs:complexType>
<xs:sequence>
<xs:element ref="response_path"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="conditions" type="xs:string">
</xs:element>
<xs:element name="response_path" type="xs:string"/>
</xs:schema>
Thanks,
Madhu
There is no way to define such a structure using XSD if the number of ruleX tags is arbitrarily defined. If you can constrain the upper bound to a maximum, and you really have to stick with ruleX naming convention, than you can define a complex type such as ruleType, then a bunch of rule1, rule2,... , ruleN elements of that type - I would call this messy... I wouldn't recommend this.
XSD (with a maximum of 6):
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="mock_rule_list">
<xs:complexType>
<xs:sequence>
<xs:element ref="rules" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="rules">
<xs:complexType>
<xs:sequence>
<xs:element ref="rule1" minOccurs="0"/>
<xs:element ref="rule2" minOccurs="0"/>
<xs:element ref="rule3" minOccurs="0"/>
<xs:element ref="rule4" minOccurs="0"/>
<xs:element ref="rule5" minOccurs="0"/>
<xs:element ref="rule6" minOccurs="0"/>
<xs:element ref="default"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="ruleType">
<xs:sequence>
<xs:element ref="conditions" minOccurs="1" maxOccurs="1"/>
<xs:element ref="response_path" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
<xs:element name="default">
<xs:complexType>
<xs:sequence>
<xs:element ref="response_path"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="conditions" type="xs:string">
</xs:element>
<xs:element name="response_path" type="xs:string"/>
<xs:element name="rule1" type="ruleType"/>
<xs:element name="rule2" type="ruleType"/>
<xs:element name="rule3" type="ruleType"/>
<xs:element name="rule4" type="ruleType"/>
<xs:element name="rule5" type="ruleType"/>
<xs:element name="rule6" type="ruleType"/>
</xs:schema>
Alternatively, you could have a tag named "rule" with a #sequence attribute.
XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="mock_rule_list">
<xs:complexType>
<xs:sequence>
<xs:element ref="rules" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="rules">
<xs:complexType>
<xs:sequence>
<xs:element ref="rule" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="default"/>
</xs:sequence>
</xs:complexType>
<xs:unique name="SequenceKey">
<xs:selector xpath="rule"/>
<xs:field xpath="#sequence"/>
</xs:unique>
</xs:element>
<xs:complexType name="ruleType">
<xs:sequence>
<xs:element ref="conditions" minOccurs="1" maxOccurs="1"/>
<xs:element ref="response_path" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
<xs:attribute name="sequence" type="xs:int" use="required"/>
</xs:complexType>
<xs:element name="default">
<xs:complexType>
<xs:sequence>
<xs:element ref="response_path"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="conditions" type="xs:string">
</xs:element>
<xs:element name="response_path" type="xs:string"/>
<xs:element name="rule" type="ruleType"/>
</xs:schema>
Sample XML:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!-- Sample XML generated by QTAssistant (http://www.paschidev.com) -->
<rules xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<rule sequence="1">
<conditions>conditions1</conditions>
<response_path>response_path1</response_path>
</rule>
<rule sequence="2">
<conditions>conditions2</conditions>
<response_path>response_path2</response_path>
</rule>
<default>
<response_path>response_path1</response_path>
</default>
</rules>
Or it could also be that one could simply use the index of the <rule/> within the parent collection .
I would like to validate this XML:
<meta>
<house>
<big ... />
<little ... />
<big ... />
</house>
<flat>
<red ... />
<red ... />
<yellow ... />
</flat>
</meta>
I wrote that.
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="meta">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="house">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name='big' />
<xs:element name='little' />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="flat">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name='red'/>
<xs:element name='yellow'/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
But that does not validate my example.
Without 'house' or 'flat', and only meta, that worked.
Where could be my problem ?
Found !
The solution: add a "xs:choice" for each "xs:sequence", like this:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="meta">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:choice>
<xs:element name="house">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:choice>
<xs:element name='big' />
<xs:element name='little' />
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="flat">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:choice>
<xs:element name='red'/>
<xs:element name='yellow'/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>