How can I determine a specific number in xsd?

I'm working on an xsd spec (for a simple game;)) that has this spec:

I have an Elem players

with an attribute number

that indicates the number of players (number from 1 and 4

). It contains elements from zero to four elements as children screenname

. These elements contain text content and a player's display name attribute that indicates the end of the game number (number between 1 and 4

).

My big problems are screen name and Intervall in type in xsd? So how do you do it?

greetings and thanks in advance

+1


source to share


2 answers


This is what I think you are describing:

<players number="2">
    <screenname endofgame="3">player screenname text content</screenname>
</players>

      

This will be the auto-generated XSD:



<?xml version="1.0" encoding="utf-8"?>
<!--W3C Schema generated by QTAssistant/W3C Schema Refactoring Module (http://www.paschidev.com)-->
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="players">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="screenname">
          <xsd:complexType>
            <xsd:simpleContent>
              <xsd:extension base="xsd:string">
                <xsd:attribute name="endofgame" type="xsd:unsignedByte" use="required" />
              </xsd:extension>
            </xsd:simpleContent>
          </xsd:complexType>
        </xsd:element>
      </xsd:sequence>
      <xsd:attribute name="number" type="xsd:unsignedByte" use="required" />
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

      

This will be one with additional restrictions as described: a num between 1 and 4

and zero to four screenname elements

. By looking before / after, you should be able to figure out which one.

<?xml version="1.0" encoding="utf-8"?>
<!--W3C Schema generated by QTAssistant/W3C Schema Refactoring Module (http://www.paschidev.com)-->
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="players">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="screenname" minOccurs="0" maxOccurs="4">
          <xsd:complexType>
            <xsd:simpleContent>
              <xsd:extension base="xsd:string">
                <xsd:attribute name="endofgame" type="Int1to4" use="required" />
              </xsd:extension>
            </xsd:simpleContent>
          </xsd:complexType>
        </xsd:element>
      </xsd:sequence>
      <xsd:attribute name="number" type="Int1to4" use="required" />
    </xsd:complexType>
  </xsd:element>
  <xsd:simpleType name="Int1to4">
    <xsd:restriction base="xsd:int">
      <xsd:minInclusive value="1"/>
      <xsd:maxInclusive value="4"/>
    </xsd:restriction>  
  </xsd:simpleType> 
</xsd:schema>

      

+1


source


To specify the number of repetitions of an element, you need to use the minOccurs and maxOccurs attributes.



0


source







All Articles