Rearraging order of elements in a sequence.

Hello,

I am attempting to rearrange the sequence order of
elements in content model.

The XML Schema specification currently has no facility
to insert an element in a specific position when using
derivation by extension.  The new element is added at
the end of the sequence.  

The closest possible construct is substitution group
which could be possible in some cases, but it only
work for global substitution and not in a local
context, but that an another issue altogether.

So, attempting to rearrange sequence elements within
the constructs of the the specification seems to be a
two step process.

I've tried a few parsers with frustrating results. The
two main validators that I've been using is XSV and
Xerces.  I have also tried Saxonica's new schema
validator too. 

I include the three schemas below. test.xsd,
extendSequence.xsd and restrictSequence.xsd

1st test.
Rearrange sequence using extension then restriction.

Extending a sequence first and then attempting to
rearrange the sequence seems to return errors in all
three validators. XSV and Saxonica errors are clearer
that those of Xerces. 

2nd test.
Rearrange sequence using restriction then extension.

The second test was to use restriction to clear the
all the elements in the restriction and then add them
back in the right order in using extension.  In this
case XSV and Saxonica seem to like this arrangement
returning no errors, but Xerces returns the same
particle is not the same as the base error and also an
extra error stating that the base content model is not
emptiable.  Which is correct as per the spec?

In this case, it seems that XSV and Saxonica  seem to
disagree with Xerces on the validity of the Schema. 
All the parsers are correct to varying degrees...I
guess that's the frustrating part. 

Does anyone have any other ideas on how to rearrange
sequence element order in such a way that all the
validators are happy?  :)

Kind regards,
Eric

Test.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
	
	<xs:complexType name="rootType">
   <xs:sequence>
       <xs:element ref="a" />
       <xs:element ref="b" minOccurs="0" />
       <xs:element ref="d" minOccurs="0" 
maxOccurs="unbounded"/>
   </xs:sequence>
   <xs:attribute name="test" />
  </xs:complexType>

<xs:element name="a"/>
<xs:element name="b"/>
<xs:element name="d"/>

</xs:schema>

extendSequence.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
	<xs:include schemaLocation="test.xsd" />
	
	<xs:element name="root2" type="extenedSequence"/>
  <xs:element name="c" type="xs:string" />
  
  <xs:complexType name="extensionTemp">
  <xs:complexContent>
    <xs:extension base="rootType">
        <xs:sequence>
          <xs:element ref="c" />
        </xs:sequence>
    </xs:extension>
  </xs:complexContent>
</xs:complexType>

<xs:complexType name="extenedSequence">
  <xs:complexContent>
    <xs:restriction base="extensionTemp">
      <xs:sequence>
        <xs:element ref="a" />
        <xs:element ref="b" minOccurs="0"/>
        <xs:element ref="c" />
        <xs:element ref="d" minOccurs="0"
maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:restriction>
  </xs:complexContent>
</xs:complexType> 
</xs:schema>

restrictSequence.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
	<xs:include schemaLocation="test.xsd" />
	

	<xs:element name="root2" type="restrictSequence"/> 
   <xs:complexType name="dumpElements">
  <xs:complexContent>
    <xs:restriction base="rootType">
      <xs:attribute name="test" />
    </xs:restriction>
  </xs:complexContent>
</xs:complexType>

<xs:complexType name="addSequence">
  <xs:complexContent>
    <xs:extension base="dumpElements">
        <xs:sequence>
          <xs:element ref="a" />
          <xs:element ref="b" minOccurs="0"/>
          <xs:element ref="c" />
          <xs:element ref="d" minOccurs="0"
maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:extension>
  </xs:complexContent>
</xs:complexType>

</xs:schema>

Received on Thursday, 15 July 2004 09:40:37 UTC