Namespace Trouble
I am new to XML. This is a homework assignment. I have given it my best but I cannot get the instance document to validate. I keep getting the error of
"Cannot find the declaration of element 'sites'."
I think I may have declared some of the namespaces incorrectly or maybe the schemaLocations. Can anyone point me in the right direction?
The homework steps:
In the sites.xml file, add a namespace declaration to the root sites element, associating the xs prefix with the URI for the XML Schema namespace. Specify the default namespace ht tp://example.com/weekendfunsnacks/sites for the file. Specify sites.xsd as the location of the schema for the default namespace.
In the sites.xsd file, in the root element, specify the target namespace as ht tp://example.com/weekendfunsnacks/sites, and then associate the prefix cc with the target namespace. Associate the prefix sm with the namespace ht tp://www.sitemaps.org/schemas/sitemap/0.9. Specify that elements are qualified by default, and that attributes are unqualified by default.
Add code to import the schema for the ht tp://www.sitemaps.org/schemas/sitemap/0.9 namespace from the location ht tp://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd.
Immediately following the declaration of the totalPages element, add a reference to the urlset element from the ht tp://www.sitemaps.org/schemas/sitemap/0.9 namespace.
The instance document:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!--
Filename: sites.xml
Supporting Files: sites.xsd
-->
<sites xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://example.com/weekendfunsnacks/sites" xs:noNamespaceSchemaLocation="sites.xsd">
<site>
<name>Weekend Fun Snacks</name>
<totalPages>127</totalPages>
<urlset xmlns:sm="http://www.sitemaps.org/schemas/sitemap/0.9" sm:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<url>
<loc>http://example.com/weekendfunsnacks/?cat=58</loc>
</url>
<url>
<loc>http://example.com/weekendfunsnacks/?cat=2</loc>
<lastmod>2017-12-29T06:03:34+00:00</lastmod>
</url>
<url>
<loc>http://example.com/weekendfunsnacks/?cat=15</loc>
<lastmod>2017-12-29T05:24:04+00:00</lastmod>
</url>
<url>
<loc>http://example.com/weekendfunsnacks/?cat=93</loc>
</url>
<url>
<loc>http://example.com/weekendfunsnacks/?cat=55</loc>
</url>
</urlset>
</site>
<site>
<name>Paleo Snacks</name>
<totalPages>52</totalPages>
<urlset xmlns:sm="http://www.sitemaps.org/schemas/sitemap/0.9" sm:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<url>
<loc>http://example.com/primalsnacks/?cat=6</loc>
</url>
<url>
<loc>http://example.com/primalsnacks/?cat=18</loc>
<lastmod>2017-09-19T17:13:19+00:00</lastmod>
</url>
<url>
<loc>http://example.com/primalsnacks/?cat=54</loc>
<lastmod>2017-09-19T15:24:01+00:00</lastmod>
</url>
<url>
<loc>http://example.com/primalsnacks/?cat=52</loc>
<lastmod>2017-09-28T21:03:11+00:00</lastmod>
</url>
<url>
<loc>http://example.com/primalsnacks/?cat=201</loc>
<lastmod>2017-10-06T07:03:26+00:00</lastmod>
</url>
<url>
<loc>http://example.com/primalsnacks/?cat=11</loc>
</url>
</urlset>
</site>
<site>
<name>Veg Snacks</name>
<totalPages>17</totalPages>
<urlset xmlns:sm="http://www.sitemaps.org/schemas/sitemap/0.9" sm:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<url>
<loc>http://example.com/vegsnacks/?cat=102</loc>
</url>
<url>
<loc>http://example.com/vegsnacks/?cat=23</loc>
</url>
<url>
<loc>http://example.com/vegsnacks/?cat=1</loc>
</url>
<url>
<loc>http://example.com/vegsnacks/?cat=55</loc>
<lastmod>2017-06-12T08:05:32+00:00</lastmod>
</url>
<url>
<loc>http://example.com/vegsnacks/?cat=201</loc>
</url>
<url>
<loc>http://example.com/vegsnacks/?cat=87</loc>
</url>
</urlset>
</site>
</sites>
The .xsd document:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="cc:http://example.com/weekendfunsnacks/sites" xmlns:sm="http://www.sitemaps.org/schemas/sitemap/0.9" attributeFormDefault="unqualified" elementFormDefault="qualified">
<xs:element name="sites">
<xs:complexType>
<xs:sequence>
<xs:element name="site" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="name"/>
<xs:element type="xs:byte" name="totalPages"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
The namespaces don't match. The schema is for namespace cc:http://example.com/weekendfunsnacks/sites
, but the instance document is in namespace http://example.com/weekendfunsnacks/sites
上一篇: 使用CUDA解非线性方程组
下一篇: 命名空间麻烦