开发者

XML Schema Multiple Elements and Attributes

I have this code:

<root>
        <skill id="1">C++</skill>
        <ski开发者_StackOverflow社区ll 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜