Discussion:
Need something like xs:sequence without order?
Felix Nensa
2010-01-28 17:04:19 UTC
Permalink
Hi experts,

I have some tricky XML that needs to be validated against an XSD, that I am
not sure how to define.
The XML could come in several variations. Some examples:

Example 1:

<SomeElement>
<A>aaa</A>
<B>bbb</B>
<C>ccc</C>
<D>ddd</D>
<D>dde</D>
</SomeElement>

Example 2:

<SomeElement>
<B>bbb</B>
<A>aaa</A>
<C>ccc</C>
<D>ddd</D>
<D>dde</D>
</SomeElement>

Example 3:

<SomeElement>
<B>bbb</B>
<A>aaa</A>
<D>ddd</D>
<D>dde</D>
</SomeElement>


The corresponding XSD that I would like to define (but of course is invalid)
would look like this:

<xs:element name="SomeElement">
<xs:complexType>
<xs:all>
<xs:element name="A" type="xs:string" minOccurs="1" maxOccurs="1" />
<xs:element name="B" type="xs:string" minOccurs="1" maxOccurs="1" />
<xs:element name="C" type="xs:string" minOccurs="0" maxOccurs="1" />

<xs:element name="D" type="xs:string" minOccurs="1"
maxOccurs="unbounded" />

</xs:all>
</xs:complexType>
</xs:element>

Any ideas how to achive the same with valid XSD?
Thanks in advance,

Felix
n***@us.ibm.com
2010-01-28 22:31:17 UTC
Permalink
In schema 1.0:

<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element ref="A" />
etc.
....references to A,B,C

In schema 1.1:

<xsd:all>
<xsd:element ref="A" />
[...]
<xsd:element ref="D" minOccurs="0" maxOccurs="2>

In other words, in schema 1.0, you can use choice, but you don't get to
tightly control the number of occurrences of each named element. Schema
1.1 can do the same, but it also allows you to use <xsd:all> with explicit
occurrence counts. That could enforce, for example, that you wanted at
most two "D" elements, regardless of order with respect to the others.
Note that XSD 1.1 is still in Candidate Recommendation status and is not
yet widely deployed.

Noah

--------------------------------------
Noah Mendelsohn
IBM Corporation
One Rogers Street
Cambridge, MA 02142
1-617-693-4036
--------------------------------------








Felix Nensa <***@zeec.biz>
Sent by: xmlschema-dev-***@w3.org
01/28/2010 12:04 PM

To: xmlschema-***@w3.org
cc: (bcc: Noah Mendelsohn/Cambridge/IBM)
Subject: Need something like xs:sequence without order?


Hi experts,

I have some tricky XML that needs to be validated against an XSD, that I
am not sure how to define.
The XML could come in several variations. Some examples:

Example 1:

<SomeElement>
<A>aaa</A>
<B>bbb</B>
<C>ccc</C>
<D>ddd</D>
<D>dde</D>
</SomeElement>

Example 2:

<SomeElement>
<B>bbb</B>
<A>aaa</A>
<C>ccc</C>
<D>ddd</D>
<D>dde</D>
</SomeElement>

Example 3:

<SomeElement>
<B>bbb</B>
<A>aaa</A>
<D>ddd</D>
<D>dde</D>
</SomeElement>


The corresponding XSD that I would like to define (but of course is
invalid) would look like this:

<xs:element name="SomeElement">
<xs:complexType>
<xs:all>
<xs:element name="A" type="xs:string" minOccurs="1" maxOccurs="1" />
<xs:element name="B" type="xs:string" minOccurs="1" maxOccurs="1" />
<xs:element name="C" type="xs:string" minOccurs="0" maxOccurs="1"
/>
<xs:element name="D" type="xs:string" minOccurs="1"
maxOccurs="unbounded" />

</xs:all>
</xs:complexType>
</xs:element>

Any ideas how to achive the same with valid XSD?
Thanks in advance,

Felix
Felix Nensa
2010-01-29 00:09:45 UTC
Permalink
Thank you for your reply.
Post by n***@us.ibm.com
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element ref="A" />
etc.
....references to A,B,C
This is quite exacly what I am doing right now as a workaround.. with the
downsides you describe.
Post by n***@us.ibm.com
<xsd:all>
<xsd:element ref="A" />
[...]
<xsd:element ref="D" minOccurs="0" maxOccurs="2>
In other words, in schema 1.0, you can use choice, but you don't get to
tightly control the number of occurrences of each named element. Schema
1.1 can do the same, but it also allows you to use <xsd:all> with explicit
occurrence counts. That could enforce, for example, that you wanted at
most two "D" elements, regardless of order with respect to the others.
Note that XSD 1.1 is still in Candidate Recommendation status and is not
yet widely deployed.
Do you know if there is any validating SAX parser for java that supports
Schema 1.1? I would like to give it a try.

Thanks for your help,

Felix
Post by n***@us.ibm.com
01/28/2010 12:04 PM
cc: (bcc: Noah Mendelsohn/Cambridge/IBM)
Subject: Need something like xs:sequence without order?
Hi experts,
I have some tricky XML that needs to be validated against an XSD, that I
am not sure how to define.
<SomeElement>
<A>aaa</A>
<B>bbb</B>
<C>ccc</C>
<D>ddd</D>
<D>dde</D>
</SomeElement>
<SomeElement>
<B>bbb</B>
<A>aaa</A>
<C>ccc</C>
<D>ddd</D>
<D>dde</D>
</SomeElement>
<SomeElement>
<B>bbb</B>
<A>aaa</A>
<D>ddd</D>
<D>dde</D>
</SomeElement>
The corresponding XSD that I would like to define (but of course is
<xs:element name="SomeElement">
<xs:complexType>
<xs:all>
<xs:element name="A" type="xs:string" minOccurs="1" maxOccurs="1" />
<xs:element name="B" type="xs:string" minOccurs="1" maxOccurs="1" />
<xs:element name="C" type="xs:string" minOccurs="0" maxOccurs="1" />
<xs:element name="D" type="xs:string" minOccurs="1"
maxOccurs="unbounded" />
</xs:all>
</xs:complexType>
</xs:element>
Any ideas how to achive the same with valid XSD?
Thanks in advance,
Felix
Michael Kay
2010-01-29 00:40:08 UTC
Permalink
Do you know if there is any validating SAX parser for java that supports
Schema 1.1? I would like to give it a try.


These features of the XSD 1.1 specification are supported in Saxon-EE 9.2.
(Saxon isn't actually an XML parser, but its schema validator will validate
the event stream produced by any SAX parser).

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay
n***@us.ibm.com
2010-01-29 01:56:27 UTC
Permalink
Michael Kay's Saxon has support for at least much of XSD 1.1. I assume
but do not know for a fact that it supports SAX. Michael follows this
list, I think, so he can give you more details if you don't find them
online.

Noah

--------------------------------------
Noah Mendelsohn
IBM Corporation
One Rogers Street
Cambridge, MA 02142
1-617-693-4036
--------------------------------------








Felix Nensa <***@zeec.biz>
01/28/2010 07:09 PM

To: ***@us.ibm.com
cc: xmlschema-***@w3.org, xmlschema-dev-***@w3.org
Subject: Re: Need something like xs:sequence without order?


Thank you for your reply.

In schema 1.0:

<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element ref="A" />
etc.
....references to A,B,C

This is quite exacly what I am doing right now as a workaround.. with the
downsides you describe.

In schema 1.1:

<xsd:all>
<xsd:element ref="A" />
[...]
<xsd:element ref="D" minOccurs="0" maxOccurs="2>

In other words, in schema 1.0, you can use choice, but you don't get to
tightly control the number of occurrences of each named element. Schema
1.1 can do the same, but it also allows you to use <xsd:all> with explicit
occurrence counts. That could enforce, for example, that you wanted at
most two "D" elements, regardless of order with respect to the others.
Note that XSD 1.1 is still in Candidate Recommendation status and is not
yet widely deployed.


Do you know if there is any validating SAX parser for java that supports
Schema 1.1? I would like to give it a try.

Thanks for your help,

Felix




Felix Nensa <***@zeec.biz>
Sent by: xmlschema-dev-***@w3.org
01/28/2010 12:04 PM

To: xmlschema-***@w3.org
cc: (bcc: Noah Mendelsohn/Cambridge/IBM)
Subject: Need something like xs:sequence without order?


Hi experts,

I have some tricky XML that needs to be validated against an XSD, that I
am not sure how to define.
The XML could come in several variations. Some examples:

Example 1:

<SomeElement>
<A>aaa</A>
<B>bbb</B>
<C>ccc</C>
<D>ddd</D>
<D>dde</D>
</SomeElement>

Example 2:

<SomeElement>
<B>bbb</B>
<A>aaa</A>
<C>ccc</C>
<D>ddd</D>
<D>dde</D>
</SomeElement>

Example 3:

<SomeElement>
<B>bbb</B>
<A>aaa</A>
<D>ddd</D>
<D>dde</D>
</SomeElement>


The corresponding XSD that I would like to define (but of course is
invalid) would look like this:

<xs:element name="SomeElement">
<xs:complexType>
<xs:all>
<xs:element name="A" type="xs:string" minOccurs="1" maxOccurs="1" />
<xs:element name="B" type="xs:string" minOccurs="1" maxOccurs="1" />
<xs:element name="C" type="xs:string" minOccurs="0" maxOccurs="1"
/>
<xs:element name="D" type="xs:string" minOccurs="1"
maxOccurs="unbounded" />

</xs:all>
</xs:complexType>
</xs:element>

Any ideas how to achive the same with valid XSD?
Thanks in advance,

Felix
Felix Nensa
2010-01-29 14:31:32 UTC
Permalink
Thanks for your advice Noah and Michael!
Post by n***@us.ibm.com
Michael Kay's Saxon has support for at least much of XSD 1.1. I assume
but do not know for a fact that it supports SAX. Michael follows this
list, I think, so he can give you more details if you don't find them
online.
Noah
--------------------------------------
Noah Mendelsohn
IBM Corporation
One Rogers Street
Cambridge, MA 02142
1-617-693-4036
--------------------------------------
01/28/2010 07:09 PM
Subject: Re: Need something like xs:sequence without order?
Thank you for your reply.
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element ref="A" />
etc.
....references to A,B,C
This is quite exacly what I am doing right now as a workaround.. with the
downsides you describe.
<xsd:all>
<xsd:element ref="A" />
[...]
<xsd:element ref="D" minOccurs="0" maxOccurs="2>
In other words, in schema 1.0, you can use choice, but you don't get to
tightly control the number of occurrences of each named element. Schema
1.1 can do the same, but it also allows you to use <xsd:all> with explicit
occurrence counts. That could enforce, for example, that you wanted at
most two "D" elements, regardless of order with respect to the others.
Note that XSD 1.1 is still in Candidate Recommendation status and is not
yet widely deployed.
Do you know if there is any validating SAX parser for java that supports
Schema 1.1? I would like to give it a try.
Thanks for your help,
Felix
01/28/2010 12:04 PM
cc: (bcc: Noah Mendelsohn/Cambridge/IBM)
Subject: Need something like xs:sequence without order?
Hi experts,
I have some tricky XML that needs to be validated against an XSD, that I
am not sure how to define.
<SomeElement>
<A>aaa</A>
<B>bbb</B>
<C>ccc</C>
<D>ddd</D>
<D>dde</D>
</SomeElement>
<SomeElement>
<B>bbb</B>
<A>aaa</A>
<C>ccc</C>
<D>ddd</D>
<D>dde</D>
</SomeElement>
<SomeElement>
<B>bbb</B>
<A>aaa</A>
<D>ddd</D>
<D>dde</D>
</SomeElement>
The corresponding XSD that I would like to define (but of course is
<xs:element name="SomeElement">
<xs:complexType>
<xs:all>
<xs:element name="A" type="xs:string" minOccurs="1" maxOccurs="1" />
<xs:element name="B" type="xs:string" minOccurs="1" maxOccurs="1" />
<xs:element name="C" type="xs:string" minOccurs="0" maxOccurs="1" />
<xs:element name="D" type="xs:string" minOccurs="1"
maxOccurs="unbounded" />
</xs:all>
</xs:complexType>
</xs:element>
Any ideas how to achive the same with valid XSD?
Thanks in advance,
Felix
Loading...