开发者

XML schema represent different fragment with ref

I have this schema :

Fragment 1:

<fragments>
<a>
<item></item>
<item></item>
<item></item>
</a>
<a>
<item></item>
<item></item>
<item></item>
</a>
<a>
<item></item>
<item></item>
<item></item>
</a>
</fragments>

fragment2:

<fragments>
<b>
<item></item>
<item></item>
<item></item>
</b>
<b>
<item></item>
<item></item>
<item></item>
</b>
<b>
<item></item>
<item></item>
<item></item>
</b>
</fragments>

fragment3:

<fragments>
<c>
<item></item>
<item></item>
<item></item>
</c>
<c>
<item></item>
<item></item>
<item></item>
</c>
<c>
<item></item>
<item></item>
<item></item>
</c>
</fragments>


    <xs:element name="Fragments">
    <xs:complexType>
        <xs:sequence>
            <xs:element ref="A"/>
            <xs:element ref="B"/>
            <xs:element ref="C"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>
<xs:element name="A">
    <xs:complexType>
        <xs:sequence>
            <xs:element ref="item" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>
<xs:element name="B">
    <xs:complexType>
        <xs:sequence>
            <xs:element ref="item" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>
<xs:element name="C">
    <xs:complexType>
        <xs:sequence>
            <xs:element ref="item" 开发者_如何学CminOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>
<xs:element name="item">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="location"/>
            <xs:element name="quantity"/>
            <xs:element name="name"/>
            <xs:element name="payment"/>
            <xs:element name="description"/>
            <xs:element name="shipping"/>
            <xs:element name="incategory" maxOccurs="unbounded"/>
            <xs:element name="mailbox"/>
        </xs:sequence>
        <xs:attribute name="id" type="xs:ID" use="required"/>
        <xs:attribute name="featured" type="xs:anySimpleType"/>
    </xs:complexType>
</xs:element>

from the answer of question how xsd can represent different xml file? I can say that I can represent A and B and C in different partitions by using ref in the schema However my question the schema use Item with ref to reduce repeating the names definition. How can I distinguish between ref that represent other fragment and ref that just used to in schema to avoid repetitions my regards


Your question is unclear to me, but I think you are asking, "How can I indicate that A, B, and C can be document roots but item cannot be a document root?"

There's not a way to indicate which global elements can be document roots. However, you can make your "internal" element declaration local to a model group and ref that model group.

Maybe something like:

<xs:element name="A">
    <xs:complexType>
        <xs:sequence>
            <group ref="itemgroup" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>

<xs:group name="itemgroup">
    <xs:sequence>
        <xs:element name="item>
            ...
        </xs:element>
    </xs:sequence>
</xs:group>

BTW, if I've understanding correctly your goal, you don't actually need the Fragments elements. Just the existence of "top-level" declarations for A, B, and C make them candidates for a document room.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜