Editor flags valid XSD as error?

The VS2005 editor complains about the following fragment of XSD:

<xs:complexType>
  <
xs:all minOccurs="1" maxOccurs="unbounded">
    <
xs:element name="Class" type="g:ClassType" minOccurs="1" maxOccurs="1"/>
    <
xs:element name="enumType" type="g:enumType" minOccurs="0" maxOccurs="1"/>
  </
xs:all>
</
xs:complexType>

The editor complains (via squigly underlining) that xs:all can't have maxOccurs > 1.  In fact it can, although the contained element declarations cannot. I've bugged this one.  Anyone care to try to repro

Thanks in advance...




Answer this question

Editor flags valid XSD as error?

  • Coder0

    Thanks for the response. It turns out that the book I referenced is simply in error. As you point out the W3C spec is pretty clear on the topic.

    So, now that I know how NOT to accomplish what I want I need to figure out the Right Way. What I want is to specify a "sequence" of elements drawn from a fixed set of (complex) types and allowing elements from this set to occur any number of times and in any order, not necessarily together in a clump.

    My current idea is to use a choice element with minOccurs = 0 and maxOccurs="unbounded", then provide the set of element types each with minOccurs = maxOccurs = 1. I think this accomplishes what I want. Is there a better "idiom" for this in XSD

    <xsd:choice minOccurs="0" maxOccurs="unbounded">
       <xsd:element name="A" type="typeA"/>
       <xsd:element name="B" type="typeB"/>
       <xsd:element name="C" type="typeC"/>
    </xsd:choice>

    This would allow a sequence of arbitrary (possibly 0) length consisting of elements A, B, C in any order, right

    Thanks again,



  • Shane_2k5

    At http://www.w3.org/TR/xmlschema-0/#AnAllGroup you can find

    ...XML Schema stipulates that an all group must appear as the sole child at the top of a content model...

    The xsd schema for xsd said:
    <xs:complexType name="all">
    ...
      <xs:restriction base="xs:explicitGroup">
    ....
       <xs:attribute name="maxOccurs" use="optional" default="1">
        <xs:simpleType>
         <xs:restriction base="xs:allNNI">
          <xs:enumeration value="1"/>
         </xs:restriction>
        </xs:simpleType>
       </xs:attribute>
    ... 
     </xs:restriction>
    ...
    </xs:complexType>

  • PupDaddy

    It's pretty much what you want. (DTD equivalent of XSD code is "(A|B|C)*" ).
  • Editor flags valid XSD as error?