【发布时间】:2020-02-16 23:11:31
【问题描述】:
我正在解决 XML 类的问题,而且我是新手。我的 XSD 文件验证。 XML 文件有以下验证错误:找不到元素“目录”的声明。 XSD 文件名是 catalog.xsd,声明元素“catalog”的 XSD 代码是
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="description" type="xs:string" />
<xs:element name="date" type="xs:string" />
<xs:attribute name="metadata" type="xs:string" />
<xs:attribute name="cid" type="cidType" />
<xs:attribute name="src" type="srcType" />
<xs:attribute name="donatedBy" type="xs:string" />
<xs:simpleType name="cidType">
<xs:restriction base="xs:ID">
<xs:pattern value="c\d{4}" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="srcType">
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z0-9]+.jpg" />
</xs:restriction>
</xs:simpleType>
<xs:complexType name="catalog">
<xs:sequence>
<xs:element name="photo" minOccurs="1" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
我已经能够解决所有其他验证错误,因此这两个文件似乎可以正确地相互引用。我错过了一步吗? “目录”元素是否应该以其他方式声明?
谢谢!
我正在添加 XML 代码,我确实认为我可能在那里遗漏了一些东西。 xml 的文件名为 catalog.xml。
<catalog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="catalog.xsd">
<photo cid="c1748" donatedBy="John Borelli">
<name metadata="tunis cooper property museum">Tunis R. Cooper property</name>
<description>
<![CDATA[
This photo was taken by John Borelli's great-grandfather. It is believed to have been taken around 1830.
David Demarest originally purchased the site of the chair factory in 1663. This site was under the ownership
of the Demarest family until 1758. The property is listed in the National and New Jersey Registers of Historic Places.
]]>
</description>
<date>circa 1830</date>
<images>
<img src="1748a.jpg" />
<img src="1748b.jpg" />
</images>
</photo>
【问题讨论】:
-
主模式需要一个 INCLUDE 来引用第二个模式。大多数模式都有可选的属性,这些属性有时会在不同的模式中声明。所以你需要在主模式中添加一个 INCLUDE 到另一个模式。它将放在架构的第二行,如下所示: