[英]Creating an XML document with more than 1 child element with XML schema
我提供了一个xml模式来创建xml文档。 根节点是电影 。 现在,此根元素具有称为movie的子元素,该子元素包含其他字符串类型的元素,每个电影也具有大约三或四个属性。 但是,在将XML文档与架构链接之后,我只能创建一个电影节点,而不能创建更多电影节点。 这是我的xml模式:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--root element movies -->
<xsd:element name="movies">
<xsd:complexType >
<xsd:all >
<xsd:element name="movie">
<xsd:complexType >
<xsd:sequence>
<!--Elements under each movie-->
<xsd:element name="title" type="xsd:string"/>
<xsd:element name="writer" type="xsd:string"/>
<xsd:element name="producer" type="xsd:string"/>
<xsd:element name="director" type="xsd:string"/>
<!--Not sure the number of actors a movie can have -->
<xsd:element name="actor" type="xsd:string" maxOccurs="unbounded"/>
<xsd:element name="poster" type="xsd:string"/>
<xsd:element name="comments" type="xsd:string"/>
</xsd:sequence>
<xsd:attribute name="type" use="required">
<!--attribute type with its options -->
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="drama"/>
<xsd:enumeration value="comedy"/>
<xsd:enumeration value="adventure"/>
<xsd:enumeration value="sci-fi"/>
<xsd:enumeration value="mystery"/>
<xsd:enumeration value="horror"/>
<xsd:enumeration value="romance"/>
<xsd:enumeration value="documentary"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="rating" use="required">
<!--attribute rating with its options -->
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="G"/>
<xsd:enumeration value="PG"/>
<xsd:enumeration value="PG-13"/>
<xsd:enumeration value="X"/>
<xsd:enumeration value="ua"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="review" use="optional">
<!--attribute review with its options -->
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="1"/>
<xsd:enumeration value="2"/>
<xsd:enumeration value="3"/>
<xsd:enumeration value="4"/>
<xsd:enumeration value="5"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="year" use="optional">
<!--attribute year -->
</xsd:attribute>
</xsd:complexType>
</xsd:element>
</xsd:all>
</xsd:complexType>
</xsd:element>
有人可以帮忙发现我的错误吗?
movie
连续播放多个movies
: (1)将xsd:all
更改为xsd:sequence
。
(2)变更
<xsd:element name="movie">
至
<xsd:element name="movie" maxOccurs="unbounded">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.