找不到元素“”的声明
No declaration found for element ' '
我刚开始使用 XML 和 XSD 文件。我要做的是使用模式验证 xml 文件。这是我的 XML 文件的开头:
<?xml version="1.0" encoding="UTF-8"?>
<movies>
<doc id="000007">
<docid>000007</docid>
<title>#73, Shanthi Nivasa</title>
<year>2007</year>
<type>movie</type>
<colorinfos>
<colorinfo>Color</colorinfo>
</colorinfos>
<genres>
<genre>Musical</genre>
</genres>
<languages>
<language>Kannada</language>
</languages>
<countries>
<country>India</country>
</countries>
<releasedates>
<releasedate country="India">14 June 2007</releasedate>
</releasedates>
<directors>
<director>Sudeep</director>
</directors>
<composers>
<composer>Bharadwaj (I)</composer>
</composers>
<cast>
<credit>
<actor>Shivarajkumar</actor>
<role>Himself</role>
</credit>
<credit>
<actor>Sudeep</actor>
<role>Raghu</role>
</credit>
<credit>
<actor>Vishnuvardhan (I)</actor>
<role>Himself</role>
</credit>
</cast>
<plot>#73, Shanthi Nivasa - the littlest things in life that give peace and happiness in a home. Although #73, Shanthi Nivasa seems to have everything on the surface, it lacks the depth of peace. Amidst the constant family fights, Raghu enters the household as the new cook and brings the ingredient of peace with him. And mysteriously, he leaves. What will #73, Shanthi Nivasa do without Raghu? Will they be able to hold their family together without this unassuming cook's presence?</plot>
<url>http://localhost:8983/solr/movie.html?000007</url>
</doc>
</movies>
这是我的模式的开始:
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="movies">
<xs:complexType>
<xs:sequence>
<xs:element name="doc" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:short" name="docid"/>
<xs:element type="xs:string" name="title"/>
<xs:element type="xs:short" name="year"/>
<xs:element type="xs:string" name="type"/>
<xs:element name="colorinfos" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="colorinfo" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="editors" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="editor" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="genres" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="genre" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="keywords" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="keyword" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="languages" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="language" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="soundmixes" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="soundmix"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="countries">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="country" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="certificates" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="certificate" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="country" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="releasedates" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="releasedate" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="country" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="runningtimes" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="runningtime" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:short">
<xs:attribute type="xs:string" name="country" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="directors" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="director" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="producers" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="producer" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="writers" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="writer" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="composers" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="composer" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="othercrew" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="credit" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="name"/>
<xs:element type="xs:string" name="job"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="cast" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="credit" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="actor"/>
<xs:element type="xs:string" name="role"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element type="xs:string" name="plot"/>
<xs:element type="xs:anyURI" name="url"/>
</xs:sequence>
<xs:attribute type="xs:short" name="id" use="optional"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
每当我尝试验证文件时遇到的错误是:
Error at line 2, column 9: no declaration found for element 'movies'
架构是自动生成的(我正在使用 XML Copy Editor)。
XML 和 XSD 文件的语法也是正确的。
您必须以某种方式将 XSD 与 XML 相关联。
一个常用的方法是 use noNamespaceSchemaLocation
for non-namespaced XML or schemaLocation
for namespaced XML。要使用此方法,请更改
<movies>
到
<movies xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="try.xsd">
您也可以使用验证器工具的机制来指定关联,但这些机制往往是特定于实现的,而上述提示往往适用于所有验证器。
另见
- How to link XML to XSD using schemaLocation or noNamespaceSchemaLocation?
- How to reference a local XML Schema file correctly?
我刚开始使用 XML 和 XSD 文件。我要做的是使用模式验证 xml 文件。这是我的 XML 文件的开头:
<?xml version="1.0" encoding="UTF-8"?>
<movies>
<doc id="000007">
<docid>000007</docid>
<title>#73, Shanthi Nivasa</title>
<year>2007</year>
<type>movie</type>
<colorinfos>
<colorinfo>Color</colorinfo>
</colorinfos>
<genres>
<genre>Musical</genre>
</genres>
<languages>
<language>Kannada</language>
</languages>
<countries>
<country>India</country>
</countries>
<releasedates>
<releasedate country="India">14 June 2007</releasedate>
</releasedates>
<directors>
<director>Sudeep</director>
</directors>
<composers>
<composer>Bharadwaj (I)</composer>
</composers>
<cast>
<credit>
<actor>Shivarajkumar</actor>
<role>Himself</role>
</credit>
<credit>
<actor>Sudeep</actor>
<role>Raghu</role>
</credit>
<credit>
<actor>Vishnuvardhan (I)</actor>
<role>Himself</role>
</credit>
</cast>
<plot>#73, Shanthi Nivasa - the littlest things in life that give peace and happiness in a home. Although #73, Shanthi Nivasa seems to have everything on the surface, it lacks the depth of peace. Amidst the constant family fights, Raghu enters the household as the new cook and brings the ingredient of peace with him. And mysteriously, he leaves. What will #73, Shanthi Nivasa do without Raghu? Will they be able to hold their family together without this unassuming cook's presence?</plot>
<url>http://localhost:8983/solr/movie.html?000007</url>
</doc>
</movies>
这是我的模式的开始:
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="movies">
<xs:complexType>
<xs:sequence>
<xs:element name="doc" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:short" name="docid"/>
<xs:element type="xs:string" name="title"/>
<xs:element type="xs:short" name="year"/>
<xs:element type="xs:string" name="type"/>
<xs:element name="colorinfos" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="colorinfo" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="editors" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="editor" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="genres" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="genre" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="keywords" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="keyword" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="languages" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="language" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="soundmixes" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="soundmix"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="countries">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="country" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="certificates" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="certificate" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="country" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="releasedates" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="releasedate" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="country" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="runningtimes" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="runningtime" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:short">
<xs:attribute type="xs:string" name="country" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="directors" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="director" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="producers" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="producer" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="writers" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="writer" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="composers" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="composer" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="othercrew" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="credit" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="name"/>
<xs:element type="xs:string" name="job"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="cast" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="credit" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="actor"/>
<xs:element type="xs:string" name="role"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element type="xs:string" name="plot"/>
<xs:element type="xs:anyURI" name="url"/>
</xs:sequence>
<xs:attribute type="xs:short" name="id" use="optional"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
每当我尝试验证文件时遇到的错误是:
Error at line 2, column 9: no declaration found for element 'movies'
架构是自动生成的(我正在使用 XML Copy Editor)。 XML 和 XSD 文件的语法也是正确的。
您必须以某种方式将 XSD 与 XML 相关联。
一个常用的方法是 use noNamespaceSchemaLocation
for non-namespaced XML or schemaLocation
for namespaced XML。要使用此方法,请更改
<movies>
到
<movies xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="try.xsd">
您也可以使用验证器工具的机制来指定关联,但这些机制往往是特定于实现的,而上述提示往往适用于所有验证器。
另见
- How to link XML to XSD using schemaLocation or noNamespaceSchemaLocation?
- How to reference a local XML Schema file correctly?