Pregunta

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>
¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top