문제

Either of the first two cases are permissible, but the latter case is not. Is it possible to create a xsd for this xml, or is it invalid?

    <book id="something" />

<!-- or -->

    <book>something</book>

<!--not -->

<
<book id="something">
    something else
</book> 

EDIT: Here's the schema I was attempting to use - I'm still very new to xml, so I can't promise it's close to being right...

<xs:simpleType name="book">
    <xs:restriction base="xs:string">
    </xs:restriction>
</xs:simpleType>


<xs:complexType name="book2">
    <xs:simpleContent>
        <xs:extension base="or:book">
            <xs:attribute name="id" type="xs:string" />
        </xs:extension>
    </xs:simpleContent>
    </xs:complexType>

<xs:complexType name="book3">
    <xs:simpleContent>
        <xs:restriction base="or:book2">
            <xs:maxLength value="0" />
        </xs:restriction>
    </xs:simpleContent>
</xs:complexType>

<xs:element name="root">
    <xs:complexType>
        <xs:choice>
            <xs:element name="book" maxOccurs="unbounded" type="or:book" />
            <xs:element name="book" maxOccurs="unbounded" type="or:book3" />
        </xs:choice>
    </xs:complexType>
</xs:element>
도움이 되었습니까?

해결책

In XSD 1.0 the rules for the content of an element can't depend on the attributes of the element. In XSD 1.1 they can (it's called conditional type assignment). So the answer to your question depends on which version of XSD you are talking about.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top