我必须从这个图中生成XML和XSD:
但会弹出错误:文件过早结束。 我还遇到另一个错误:xsd:all必须以结束标记终止 我的代码是否正确?
实体关系约束:
1. A theater can have at least 1 screen but not more than 3.
2. A screen may have many shows and sometimes it may not have any show.
show-time example - 10 AM, 12 PM etc.
3. A show has information on the movie which has the director name, title
and the release date which can occur in any order.
4. A movie will have actors and actors may have many actor's name.
代码:
<?xml version="1.0" encoding="UTF-8"?>
<theater>
<name>rajat</name>
<address>mumbai</address>
<phone>987654</phone>
<screen>
<seats>30</seats>
<width>30</width>
<show>
<show-time>10 AM</show-time>
<movie>
<director>jade</director>
<title>game</title>
<release-date>10/10/2017</release-date>
<actors>
<name>james</name>
<name>aaron</name>
</actors>
</movie>
</show>
</screen>
</theater>
XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="https://www.w3.org/2001/XMLSchema"
attributeFormDefault="unqualified" elementFormDefault="qualified">
<xsd:element name="theater">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="address" type="xsd:string"/>
<xsd:element name="phone" type="xsd:long"/>
<xsd:element name="screen" maxOccurs="3"/>
<xsd:complexType>
<xsd:sequence>
<xsd:element name="seats" type="xsd:byte"/>
<xsd:element name="width" type="xsd:byte"/>
<xsd:element name="show" minOccurs="0"/>
<xsd:complexType>
<xsd:sequence>
<xsd:element name="show-time" type="xsd:string" maxOccurs="unbounded"
minOccurs="0"/>
<xsd:element name="movie"/>
<xsd:complexType>
<xsd:all>
<xsd:element name="director" type="xsd:string"/>
<xsd:element name="title" type="xsd:string"/>
<xsd:element name="release-date" type="xsd:string"/>
<xsd:element name="actors"/>
<xsd:complexType>
<xsd:sequence>
<xsd:element name="name" type="xsd:string" maxOccurs="unbounded"
minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:all>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
答案 0 :(得分:0)
<强>首先强>
xmlns:xsd="https://www.w3.org/2001/XMLSchema"
必须是
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
<强>第二强>
<xsd:element name="screen" maxOccurs="3"/>
<xsd:complexType>
必须是
<xsd:element name="screen" maxOccurs="3">
<xsd:complexType>
上述类型的错误发生在多个地方。
<强>第三强>
最后,使用XML编辑器并平衡结束标记。
总而言之,这里修复的XSD在语法上是有效的:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
attributeFormDefault="unqualified" elementFormDefault="qualified">
<xsd:element name="theater">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="address" type="xsd:string"/>
<xsd:element name="phone" type="xsd:long"/>
<xsd:element name="screen" maxOccurs="3">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="seats" type="xsd:byte"/>
<xsd:element name="width" type="xsd:byte"/>
<xsd:element name="show" minOccurs="0">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="show-time" type="xsd:string"
maxOccurs="unbounded"
minOccurs="0"/>
<xsd:element name="movie">
<xsd:complexType>
<xsd:all>
<xsd:element name="director" type="xsd:string"/>
<xsd:element name="title" type="xsd:string"/>
<xsd:element name="release-date" type="xsd:string"/>
<xsd:element name="actors">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="name" type="xsd:string"
maxOccurs="unbounded"
minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:all>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
对您的XML文档进行验证仍然可以作为练习。