Restricting an elements that has been extended in XSD - xsd

I am trying to create reusable element declarations for a web service to insert and update. I have the following declarations:
<xs:complexType name="commonEntity">
<xs:sequence>
<xs:element name="id" type="snt-common:id" minOccurs="0"
maxOccurs="1" />
<xs:element name="createdByID" type="snt-common:id"
minOccurs="0" maxOccurs="1" />
<xs:element name="createDate" type="snt-common:dateTime"
minOccurs="0" maxOccurs="1" />
<xs:element name="modifiedByID" type="snt-common:id"
minOccurs="0" maxOccurs="1" />
<xs:element name="modifyDate" type="snt-common:dateTime"
minOccurs="0" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="contact">
<xs:complexContent>
<xs:extension base="snt-common:commonEntity">
<xs:sequence>
<xs:element name="firstName" type="snt-common:string255"
minOccurs="0" maxOccurs="1" />
<xs:element name="lastName" type="snt-common:string255"
minOccurs="0" maxOccurs="1" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element id="update" name="ContactUpdateRequest">
<xs:complexType>
<xs:complexContent>
<xs:restriction base="snt:contact">
<xs:sequence>
<xs:element name="id" type="snt-common:id" minOccurs="1"
maxOccurs="1" />
<xs:element name="modifyDate" type="snt-common:dateTime"
minOccurs="1" maxOccurs="1" />
<xs:element name="firstName" type="snt-common:string255"
minOccurs="0" maxOccurs="1" />
<xs:element name="lastName" type="snt-common:string255"
minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:element>
<xs:element id="insert" name="ContactInsertRequest">
<xs:complexType>
<xs:complexContent>
<xs:restriction base="snt:contact">
<xs:sequence>
<xs:element name="firstName" type="snt-common:string255"
minOccurs="0" maxOccurs="1" />
<xs:element name="lastName" type="snt-common:string255"
minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:element>
What I am trying to achieve is to create an insert and an update request, both of which are restrictions of contact. Contact in turn is an extension of commonEntity, which is used for all schemas as a base.
Insert works fine since there are no additional restrictions, but for update we require the id and modifyDate (this is how we enforce versioning) in the request. However, I get the following error when validating the schema:
Error for type '#AnonType_ContactUpdateRequest'. The particle of the type is not a valid restriction of the particle of
the base.
It seems as though I cannot restrict elements in the base element, commonEntity. I have tried reordering without success. Is this a nuance of XSD or am I missing something?
Update:
common.xsd
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" targetNamespace="http://predictivesolutions.com/schema/common"
xmlns:snt-common="http://predictivesolutions.com/schema/common"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jaxb:extensionBindingPrefixes="xjc" elementFormDefault="qualified"
jaxb:version="2.0">
<xs:annotation>
<xs:appinfo>
<jaxb:globalBindings>
<xjc:javaType name="java.util.Calendar" xmlType="xs:dateTime"
adapter="com.ps.snt.ws.util.CalendarDateTimeAdapter" />
<xjc:javaType name="java.util.Calendar" xmlType="xs:date"
adapter="com.ps.snt.ws.util.CalendarDateAdapter" />
</jaxb:globalBindings>
</xs:appinfo>
</xs:annotation>
<!-- Creating this id type to use in the event we need to change to a long,
we can just do it here. -->
<xs:simpleType name="id">
<xs:restriction base="xs:integer">
<xs:minInclusive value="1"></xs:minInclusive>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="dateTime">
<xs:restriction base="xs:dateTime">
<!-- 2013-11-06T11:17:17.043-05:00 -->
<xs:pattern value="\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d.\d\d\d[+\-]\d\d:\d\d" />
<!-- 2013-11-06T11:17:17-05:00 -->
<xs:pattern value="\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d[+\-]\d\d:\d\d" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="string255">
<xs:restriction base="xs:string">
<xs:maxLength value="255" />
</xs:restriction>
</xs:simpleType>
<xs:complexType name="commonEntity">
<xs:sequence>
<xs:element name="id" type="snt-common:id" minOccurs="0"
maxOccurs="1" />
<xs:element name="createdByID" type="snt-common:id"
minOccurs="0" maxOccurs="1" />
<xs:element name="createDate" type="snt-common:dateTime"
minOccurs="0" maxOccurs="1" />
<xs:element name="modifiedByID" type="snt-common:id"
minOccurs="0" maxOccurs="1" />
<xs:element name="modifyDate" type="snt-common:dateTime"
minOccurs="0" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:schema>
contact.xsd
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://predictivesolutions.com/schema/v1_1" xmlns:snt="http://predictivesolutions.com/schema/v1_1"
xmlns:snt-common="http://predictivesolutions.com/schema/common"
elementFormDefault="qualified">
<xs:import namespace="http://predictivesolutions.com/schema/common"
schemaLocation="../common.xsd" />
<xs:complexType name="contact">
<xs:complexContent>
<xs:extension base="snt-common:commonEntity">
<xs:sequence>
<xs:element name="firstName" type="snt-common:string255"
minOccurs="0" maxOccurs="1" />
<xs:element name="lastName" type="snt-common:string255"
minOccurs="0" maxOccurs="1" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<!-- For transporting data -->
<xs:element id="contact" name="contact" type="snt:contact">
</xs:element>
</xs:schema>
ContactService.xsd
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://predictivesolutions.com/schema/v1_1" xmlns:snt="http://predictivesolutions.com/schema/v1_1"
xmlns:snt-common="http://predictivesolutions.com/schema/common"
elementFormDefault="qualified">
<xs:import namespace="http://predictivesolutions.com/schema/common"
schemaLocation="../common.xsd" />
<xs:include schemaLocation="contact.xsd" />
<!-- Request/Response for inserting data -->
<xs:element id="insert" name="ContactInsertRequest">
<xs:complexType>
<xs:complexContent>
<xs:restriction base="snt:contact">
<xs:sequence>
<xs:element name="firstName" type="snt-common:string255"
minOccurs="0" maxOccurs="1" />
<xs:element name="lastName" type="snt-common:string255"
minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:element>
<!-- Request/Response for updating data -->
<xs:element id="update" name="ContactUpdateRequest">
<xs:complexType>
<xs:complexContent>
<xs:restriction base="snt:contact">
<xs:sequence>
<xs:element name="id" type="snt-common:id" minOccurs="1"
maxOccurs="1" />
<xs:element name="modifyDate" type="snt-common:dateTime"
minOccurs="1" maxOccurs="1" />
<xs:element name="firstName" type="snt-common:string255"
minOccurs="0" maxOccurs="1" />
<xs:element name="lastName" type="snt-common:string255"
minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
</xs:schema>

Related

Adding intellisense on custom NLog targets

I'm looking to add a thirdparty target type to NLog.xsd. You would normally create a nlog.config file like this:
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
...>
...
<targets>
<target name="file" xsi:type="File" />
</targets>
...
</nlog>
Now I want to add a new target:
<targets>
<target name="file" xsi:type="File" />
<target name="file" xsi:type="MyTarget" />
</targets>
XSD validation warns inside Visual Studio, since MyTarget isn't defined anywhere. I have tried adding MyTarget to NLog.xsd and reference the updated NLog.xsd, but then I get no intellisense what so ever:
<nlog xmlns="http://my-project.com/NLog.xsd" ...>
Any ideas how to implement this?
The custom Syslog target (NLog.Targets.Syslog) has created a custom XSD that extends the XSD of NLog.
Content:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="NLog.Targets.Syslog"
elementFormDefault="qualified"
targetNamespace="http://www.nlog-project.org/schemas/NLog.Targets.Syslog.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sl="http://www.nlog-project.org/schemas/NLog.Targets.Syslog.xsd"
xmlns:nlog="http://www.nlog-project.org/schemas/NLog.xsd">
<xs:import namespace="http://www.nlog-project.org/schemas/NLog.xsd" />
<xs:complexType name="Syslog">
<xs:complexContent>
<xs:extension base="nlog:Target">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="name" type="xs:string" minOccurs="0" maxOccurs="1" />
<xs:element name="layout" type="nlog:Layout" minOccurs="0" maxOccurs="1" />
<xs:element name="enforcement" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="throttling" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="limit" type="xs:integer" minOccurs="0" maxOccurs="1" />
<xs:element name="strategy" type="xs:string" minOccurs="0" maxOccurs="1" />
<xs:element name="delay" type="xs:decimal" minOccurs="0" maxOccurs="1" />
</xs:choice>
<xs:attribute name="limit" type="xs:integer" />
<xs:attribute name="strategy" type="xs:string" />
<xs:attribute name="delay" type="xs:decimal" />
</xs:complexType>
</xs:element>
<xs:element name="messageProcessors" type="xs:integer" minOccurs="0" maxOccurs="1" />
<xs:element name="splitOnNewLine" type="xs:boolean" minOccurs="0" maxOccurs="1" />
<xs:element name="transliterate" type="xs:boolean" minOccurs="0" maxOccurs="1" />
<xs:element name="replaceInvalidCharacters" type="xs:boolean" minOccurs="0" maxOccurs="1" />
<xs:element name="truncateFieldsToMaxLength" type="xs:boolean" minOccurs="0" maxOccurs="1" />
<xs:element name="truncateMessageTo" type="xs:integer" minOccurs="0" maxOccurs="1" />
</xs:choice>
<xs:attribute name="messageProcessors" type="xs:integer" />
<xs:attribute name="splitOnNewLine" type="xs:boolean" />
<xs:attribute name="transliterate" type="xs:boolean" />
<xs:attribute name="replaceInvalidCharacters" type="xs:boolean" />
<xs:attribute name="truncateFieldsToMaxLength" type="xs:boolean" />
<xs:attribute name="truncateMessageTo" type="xs:integer" />
</xs:complexType>
</xs:element>
<xs:element name="messageCreation" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="facility" type="xs:string" minOccurs="0" maxOccurs="1" />
<xs:element name="rfc" type="xs:string" minOccurs="0" maxOccurs="1" />
<xs:element name="rfc3164" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="hostname" type="xs:string" minOccurs="0" maxOccurs="1" />
<xs:element name="tag" type="xs:string" minOccurs="0" maxOccurs="1" />
</xs:choice>
<xs:attribute name="hostname" type="xs:string" />
<xs:attribute name="tag" type="xs:string" />
</xs:complexType>
</xs:element>
<xs:element name="rfc5424" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="hostname" type="nlog:Layout" minOccurs="0" maxOccurs="1" />
<xs:element name="appName" type="nlog:Layout" minOccurs="0" maxOccurs="1" />
<xs:element name="procId" type="nlog:Layout" minOccurs="0" maxOccurs="1" />
<xs:element name="msgId" type="nlog:Layout" minOccurs="0" maxOccurs="1" />
<xs:element name="structuredData" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="1">
<xs:element name="fromEventProperties" type="nlog:Layout" minOccurs="0" maxOccurs="1" />
<xs:element name="sdElement" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="sdParam" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="name" type="xs:string" use="required" />
<xs:attribute name="value" type="xs:string" use="required" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="sdId" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="disableBom" type="xs:boolean" minOccurs="0" maxOccurs="1" />
</xs:choice>
<xs:attribute name="hostname" type="nlog:SimpleLayoutAttribute" />
<xs:attribute name="appName" type="nlog:SimpleLayoutAttribute" />
<xs:attribute name="procId" type="nlog:SimpleLayoutAttribute" />
<xs:attribute name="msgId" type="nlog:SimpleLayoutAttribute" />
<xs:attribute name="disableBom" type="xs:boolean" />
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="messageSend" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="protocol" type="xs:string" minOccurs="0" maxOccurs="1" />
<xs:element name="udp" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="server" type="xs:string" minOccurs="1" maxOccurs="1" />
<xs:element name="port" type="xs:integer" minOccurs="0" maxOccurs="1" />
</xs:choice>
<xs:attribute name="server" type="xs:string" />
<xs:attribute name="port" type="xs:integer" />
</xs:complexType>
</xs:element>
<xs:element name="tcp" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="server" type="xs:string" minOccurs="1" maxOccurs="1" />
<xs:element name="port" type="xs:integer" minOccurs="0" maxOccurs="1" />
<xs:element name="keepAlive" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="enabled" type="xs:boolean" minOccurs="0" maxOccurs="1" />
<xs:element name="timeout" type="xs:integer" minOccurs="0" maxOccurs="1" />
<xs:element name="interval" type="xs:integer" minOccurs="0" maxOccurs="1" />
</xs:choice>
<xs:attribute name="enabled" type="xs:boolean" />
<xs:attribute name="timeout" type="xs:integer" />
<xs:attribute name="interval" type="xs:integer" />
</xs:complexType>
</xs:element>
<xs:element name="reconnectInterval" type="xs:integer" minOccurs="0" maxOccurs="1" />
<xs:element name="useTls" type="xs:boolean" minOccurs="0" maxOccurs="1" />
<xs:element name="framing" type="xs:string" minOccurs="0" maxOccurs="1" />
<xs:element name="dataChunkSize" type="xs:integer" minOccurs="0" maxOccurs="1" />
</xs:choice>
<xs:attribute name="server" type="xs:string" />
<xs:attribute name="port" type="xs:integer" />
<xs:attribute name="reconnectInterval" type="xs:integer" />
<xs:attribute name="useTls" type="xs:boolean" />
<xs:attribute name="framing" type="xs:string" />
<xs:attribute name="dataChunkSize" type="xs:integer" />
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:choice>
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="layout" type="nlog:SimpleLayoutAttribute" />
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
Usage: (this one is published on http://nlog-project.org/)
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sl="http://www.nlog-project.org/schemas/NLog.Targets.Syslog.xsd">
and
<target xsi:type="sl:Syslog" name="syslog3164-tgt">
instead of
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
See also https://github.com/NLog/NLog.github.io/pull/56
Update: Visual Studio also needed this:
<nlog xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.Targets.Syslog.xsd http://www.nlog-project.org/schemas/NLog.Targets.Syslog.xsd" .. >

Change minimum restriction of a type within a complex type

I have a complex type called SafetyTiming and it has 2 elements value and margin. Both value and margin are based on a simpletype called Timing.
<xs:simpleType name="Timing">
<xs:restriction base="xs:unsignedInt">
<xs:minInclusive value="0" />
<xs:maxInclusive value="999" />
</xs:restriction>
</xs:simpleType>
<xs:complexType name="SafetyTiming">
<xs:sequence>
<xs:element name="Value" type="Timing" minOccurs="1" maxOccurs="1" />
<xs:element name="Margin" type="Timing" minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
<xs:element name="SafetyTimings">
<xs:complexType>
<xs:all>
<xs:element name="A" type="SafetyTiming" minOccurs="1" maxOccurs="1" />
<xs:element name="B" type="SafetyTiming" minOccurs="1" maxOccurs="1" />
<xs:element name="C" type="SafetyTiming" minOccurs="1" maxOccurs="1" />
<xs:element name="D" type="SafetyTiming" minOccurs="1" maxOccurs="1" />
</xs:all>
</xs:complexType>
</xs:element>
This was fine until I found out that elements A and B need to have a minimum of 0 for simpletype "value" and, C and D a minimum of 1.
How can I elegantly solve this?
I tried the following but I think it looks rather messy and I wonder if there is a better solution.
<!--Safety timing type containing the timing value (minimum 0) and the value margin-->
<xs:complexType name="SafetyTiming_min0">
<xs:sequence>
<xs:element name="Value" type="Timing" minOccurs="1" maxOccurs="1" />
<xs:element name="Margin" type="Timing" minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
<!--Safety timing type containing the timing value (minimum 1) and the value margin-->
<xs:complexType name="SafetyTiming_min1">
<xs:sequence>
<xs:element name="Value" minOccurs="1" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="Timing">
<xs:minInclusive value="1" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Margin" type="Timing" minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
You can derive a restricted type from Timing:
<xs:simpleType name="CDTiming">
<xs:restriction base="Timing">
<xs:minInclusive value="1" />
</xs:restriction>
</xs:simpleType>
It's simpler to just create a new type for C and D which has the restricted Value:
<xs:complexType name="CDSafetyTiming">
<xs:sequence>
<xs:element name="Value" type="CDTiming" minOccurs="1" maxOccurs="1" />
<xs:element name="Margin" type="Timing" minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
You don't need to change anything for A and B since the original type already has a minimum of 0.
If you can change your original XSD, you can use the new type in the definition of your elements:
<xs:element name="SafetyTimings">
<xs:complexType>
<xs:all>
<xs:element name="A" type="SafetyTiming" minOccurs="1" maxOccurs="1" />
<xs:element name="B" type="SafetyTiming" minOccurs="1" maxOccurs="1" />
<xs:element name="C" type="CDSafetyTiming" minOccurs="1" maxOccurs="1" />
<xs:element name="D" type="CDSafetyTiming" minOccurs="1" maxOccurs="1" />
</xs:all>
</xs:complexType>
</xs:element>

XSD - how to add two 'ref' to the same element

I have been trying to form this XSD, can someone help please...
I have an element 'country' as below:
<xs:element name="country">
<xs:complexType>
<xs:sequence>
<xs:element name="id" type="xs:long" minOccurs="0" />
<xs:element name="isoCode" type="xs:string" minOccurs="0" />
<xs:element name="currencyCode" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
Now, I need to form XSD with two elements, 'source country' and 'destination country' which should both reference to 'country'. Can someone please help me to form that XSD.
<xs:element name="crossCountries">
<xs:complexType>
<xs:sequence>
<xs:element name="id" type="xs:long" minOccurs="0" />
<xs:element ref="country" /> <!-- Source Country -->
<xs:element ref="country" /> <!-- Destination Country -->
</xs:sequence>
</xs:complexType>
</xs:element>
You cannot reference an element and assign a different tag name to that reference. What you want to do instead is to define the content model for that element (a complex type would do) and reuse that under differently named tags.
<xs:complexType name="country">
<xs:sequence>
<xs:element name="id" type="xs:long" minOccurs="0" />
<xs:element name="isoCode" type="xs:string" minOccurs="0" />
<xs:element name="currencyCode" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
Then:
<xs:element name="crossCountries">
<xs:complexType>
<xs:sequence>
<xs:element name="id" type="xs:long" minOccurs="0" />
<xs:element name="sourceCountry" type="country" /> <!-- Source Country -->
<xs:element name="destinationCountry" type="country" /> <!-- Destination Country -->
</xs:sequence>
</xs:complexType>
</xs:element>

Nested sequence in XSD

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>

XML Schema with complext type containing <xs:all> and <xs:any>?

I want to define a complex type that contains elements that may or may not exist, and also allows for additional undefined elements so I've got something like this:
<xs:complexType name="MyType">
<xs:sequence>
<xs:element name="A" type="xs:float" minOccurs="0" maxOccurs="1" />
<xs:element name="B" type="xs:float" minOccurs="0" maxOccurs="1" />
<xs:element name="C" type="xs:float" minOccurs="0" maxOccurs="1" />
<xs:any minOccurs="0" processContents="skip"/>
</xs:sequence>
</xs:complexType>
I don't want to force the order using <xs:sequence> so I want to change the <xs:sequence> to <xs:all> but then <xs:any> isn't allowed. Is there some way to accomplish this?
To allow any order, use this:
<xs:complexType name="MyType">
<xs:all minOccurs="1" maxOccurs="1">
<xs:element name="A" type="xs:float" minOccurs="0" maxOccurs="1" />
<xs:element name="B" type="xs:float" minOccurs="0" maxOccurs="1" />
<xs:element name="C" type="xs:float" minOccurs="0" maxOccurs="1" />
</xs:all>
</xs:complexType>
But then, you can't have an <any> inside an <all>.
Nor can you have them both inside one type, either directly or as an extension.

Resources