#StackBounty: #xml #xsd How to add xs:occurs attribute group to my element declaration?

Bounty: 50

I am defining a complex element sequence_T that I would like to add minOccurs/maxOccurs attributes to that have the same semantics as those of the occurs group defined in https://www.w3.org/2001/XMLSchema.xsd, but I am encountering difficulties that seem to exceed my current skill level.

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://versionschema.org/xmlns"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsv="http://www.w3.org/2007/XMLSchema-versioning" xsv:minVersion="1.1"
    xmlns:vs="http://versionschema.org/xmlns" elementFormDefault="qualified"
    attributeFormDefault="unqualified" xml:lang="en" version="Experimental.0 {VSchemaInDev.0}"
    >

    <xsd:complexType name="sequence_T" final="#all">

        <xsd:annotation>
            <xsd:documentation xml:lang="en">
                Declares an ordered list of elements.
            </xsd:documentation>
        </xsd:annotation>

        <xsd:sequence>
            <xsd:choice minOccurs="0" maxOccurs="unbounded">
                <xsd:group ref="vs:baseelementsGroup"/>
                <xsd:group ref="vs:controlGroup"/>
                <xsd:group ref="vs:ruleelementsGroup"/>
            </xsd:choice>
        </xsd:sequence>

        <xsd:attributeGroup ref="vs:annotationsAttributeGroup"/>
        <xsd:attributeGroup ref="xsd:occurs"/>

    </xsd:complexType>
</xsd:schema>

I am getting “cannot resolve the name ‘xsd:occurs’ to a(n) ‘attribute group’ component”. Any clues how to add these attributes?

I do have this work-around:

<xsd:attributeGroup name="minmaxAttributesGroup">

    <xsd:attribute name="minOccurs" type="xsd:nonNegativeInteger" default="1"/>
    <xsd:attribute name="maxOccurs" type="xsd:nonNegativeInteger" default="1"/>
    <xsd:attribute name="maxOccursUnbounded" type="xsd:boolean" default="false"/>

</xsd:attributeGroup>

But maxOccursUnbounded="true" is not as semantically clean as maxOccurs="unbounded".


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.