2

I have this code:

<root>
        <skill id="1">C++</skill>
        <skill id="2">C#</skill>
        <skill id="3">Java</skill>
        <skill id="4">PHP</skill>
        <skill id="5">MYSQL</skill>
        <skill id="6">HTML</skill>
        <skill id="7">CSS</skill>
        <skill id="8">JavaScript</skill>
        <skill id="9">XML</skill>
</root>

I'm trying to create a schema to this and I'm not quite sure how to declare multiple elements with same name and it's attributes. XML Schema: how to have multiple identical elements? but was unsure exactly what was going on. Do I need maxOccurs when I put a minOccurs? And in the link above I don't understand the attribute part in the schema could somebody help / elaborate please?

Community
  • 1
  • 1
Howdy_McGee
  • 10,422
  • 29
  • 111
  • 186

1 Answers1

4

The following declares the root element, which can only occur once and must be specified, and a sequence of skill elements with an id attribute of type xs:IDREF.

xs:attribute declares an attribute for the element. The name attribute specifies the attribute name. The type attribute specifies the data type.

<xs:element name="root" minOccurs="1">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="skill" minOccurs="1" maxOccurs="unbounded">
                <xs:complexType>
                    <xs:attribute name="id" type="xs:IDREF"/>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>

Do I need maxOccurs when I put a minOccurs?

No, you don't need to have maxOccurs. There is an implicit maxOccurs="1" if you don't specify it.

Mads Hansen
  • 63,927
  • 12
  • 112
  • 147