Error: It was detected that 'sites' has no namespace, but components with no target namespace are not referenceable from schema document
Asked Answered
D

2

10

I have been working on this "advanced" schema for days with the flu and I cannot figure out why it keeps telling me that "sites" is not found. I re-read the chapter and even created a copy to experiment with (which worked before) and I do not understand. I am trying to import and combine schemas and I am not sure how to get it to work properly... Here are the errors:

Ln 16 Col 84 - cvc-elt.1: Cannot find the declaration of element 'sites'. 1 Errors [Xerces-J 2.9.1] Validating XML Schema "sites.xsd" ... Ln 32 Col 49 - src-resolve.4.1: Error resolving component 'sites'. It was detected that 'sites' has no namespace, but components with no target namespace are not referenceable from schema document.

If 'sites' is intended to have a namespace, perhaps a prefix needs to be provided. If it is intended that 'sites' has no namespace, then an 'import' without a "namespace" attribute should be added

Here is the schema:

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:cc="http://example.com/weekendfunsnacks/sites/ns"
      targetNamespace="http://example.com/weekendfunsnacks/sites"
      xmlns:sm="http://www.sitemaps.org/schemas/sitemap/0.9/ns"
            elementFormDefault="qualified" attributeFormDefault="unqualified">

 <xs:import namespace="http://www.sitemaps.org/schemas/sitemap/0.9"
             schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" />

   <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:element ref="sites"  />
                  </xs:sequence>
               </xs:complexType>
            </xs:element>
         </xs:sequence>
      </xs:complexType>
   </xs:element>
</xs:schema>​

And here is the XML:

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<sites xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xs="http://example.com/weekendfunsnacks/sites/ns"
       xsi:schemaLocation="http://example.com/weekendfunsnacks/sites/ns sites.xsd">
    <site>
        <name>Weekend Fun Snacks</name>
        <totalPages>127</totalPages>
    <urlset xmlns:sm="http://www.sitemaps.org/schemas/sitemap/0.9/ns">
         <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/ns">
         <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/ns">
         <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>​
Determinable answered 2/10, 2015 at 4:7 Comment(0)
D
12

Your XSD has a targetNamespace, so your ref="sites" has to reference that namespace.

Define a namespace prefix, say w:, to be the same as the target namespace, and then use it in the reference: ref="w:sites":

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
             targetNamespace="http://example.com/weekendfunsnacks/sites"
             xmlns:w="http://example.com/weekendfunsnacks/sites"
             elementFormDefault="qualified" attributeFormDefault="unqualified">
    
  <xs:import namespace="http://www.sitemaps.org/schemas/sitemap/0.9"
             schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" />
  
  <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:element ref="w:sites"  />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>
  
  
D answered 2/10, 2015 at 11:34 Comment(4)
Thank you very much. But now it is saying that "[Xerces-J 2.9.1] Checking "sites.xml" for Well-formedness ... Ln 16 Col 84 - The prefix "xsi" for attribute "xsi:schemaLocation" associated with an element type "sites" is not bound. 1 Error" And so the XML is still not validating.Determinable
The above XSD itself is well-formed and correct. Your new error is coming from the parsing of your XML file and indicates that you must add this declaration to the root element of "sites.xml": xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance".D
Thank you very much for the help. I think I understand a lot more. However, the XML file is still not validating: <sites xmlns:xsi="w3.org/2001/XMLSchema-instance" xmlns="example.com/weekendfunsnacks/sites/ns" xsi:schemaLocation="example.com/weekendfunsnacks/sites/ns sites.xsd"> .... It says: "[Xerces-J 2.9.1] Checking "sites.xml" for Well-formedness ... Ln 93 Col 9 - Content is not allowed in trailing section. 1 Error"Determinable
Again, the above XSD itself is well-formed and correct. Your new error indicates that you've introduced some syntactical mistake in applying this answer. ...I see you've now accepted the answer and so have presumably found the syntax error. Good.D
G
0

Inside your <xs:schema add xmlns with same value you have for targetNamespace, for your example:

xmlns="http://example.com/weekendfunsnacks/sites"

So result will be like:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:cc="http://example.com/weekendfunsnacks/sites/ns"
  targetNamespace="http://example.com/weekendfunsnacks/sites" 
  xmlns="http://example.com/weekendfunsnacks/sites" 
  ....
Gustation answered 13/4, 2022 at 12:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.