xsd - Not sure why my XML file is coming up as invalid/no grammar found and why my schema is not validating either? -


i new xml, have been unable figure out these errors. first time attempting create "advanced" schemas, uncertain importing , how reference "urlset" in schema... these errors:

ln 14 col 7 - document invalid: no grammar found.

ln 14 col 7 - document root element "sites", must match doctype root "null". 2 errors

...

ln 31 col 98 - s4s-att-invalid-value: invalid attribute value 'ref' in element 'element'. recorded reason: cvc-datatype-valid.1.2.1: 'http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd' not valid value 'qname'. 1 error

here code:

<xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema"       xmlns:cc="http://example.com/weekendfunsnacks/sites/ns"       xmlns:sm="http://www.sitemaps.org/schemas/sitemap/0.9"             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="http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" />                   </xs:sequence>                </xs:complextype>             </xs:element>          </xs:sequence>       </xs:complextype>    </xs:element> </xs:schema>​ 
<sites xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"         xmlns:crs="http://example.com/weekendfunsnacks/sites/ns">     <site>         <name>weekend fun snacks</name>         <totalpages>127</totalpages>     <urlset xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"               xsi:schemalocation="http://www.sitemaps.org/schemas/sitemap/0.9                   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:xsi="http://www.w3.org/2001/xmlschema-instance"               xsi:schemalocation="http://www.sitemaps.org/schemas/sitemap/0.9                   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:xsi="http://www.w3.org/2001/xmlschema-instance"               xsi:schemalocation="http://www.sitemaps.org/schemas/sitemap/0.9                   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>​ 

any or enlightenment appreciated, thank you.

you need perform fixture both in schema , in xml:

first, in schema:

you need "call" reference urlset element defined in sitemap schema importing : <xs:element ref="sm:urlset" /> instead of <xs:element ref="http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" />.

a point notice here elements importing sitemap.xsd bound the namespacehttp://www.sitemaps.org/schemas/sitemap/0.9/ns need add prefix sm: urlset element.

you need define target namespace own schema, adding targetnamespace="http://example.com/weekendfunsnacks/sites/ns" root element of schema.

the corrected schema be:

<?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema"     xmlns:cc="http://example.com/weekendfunsnacks/sites/ns"     xmlns:sm="http://www.sitemaps.org/schemas/sitemap/0.9"     elementformdefault="qualified" attributeformdefault="unqualified"      targetnamespace="http://example.com/weekendfunsnacks/sites/ns">      <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="sm:urlset" />                         </xs:sequence>                     </xs:complextype>                 </xs:element>             </xs:sequence>         </xs:complextype>     </xs:element> </xs:schema> 

then xml instance:

now fixes have been made in schema, need call appropriately xml. goes wrong haven't set schemalocation on <sites> element. correct issue:

<sites xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"  xsi:schemalocation="http://example.com/weekendfunsnacks/sites/ns funsnacks.xsd"  xmlns="http://example.com/weekendfunsnacks/sites/ns"  xmlns:sm="http://www.sitemaps.org/schemas/sitemap/0.9"> 

notice @ same time have added namespace declaration (xmlns:sm) sitemap.xsd schema. leads next fix undertaken - have use namespace prefix <urlset> element. example of fixup provided below. not need anymore xsi-related declaration on these elements:

    <sm:urlset>         <sm:url>             <sm:loc>http://example.com/vegsnacks/?cat=55</sm:loc>             <sm:lastmod>2017-06-12t08:05:32+00:00</sm:lastmod>         </sm:url>         <!-- , on ... -->     </sm:urlset> 

your corrected input example turn to:

<?xml version="1.0" encoding="utf-8"?>  <sites xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"  xsi:schemalocation="http://example.com/weekendfunsnacks/sites/ns funsnacks.xsd"  xmlns="http://example.com/weekendfunsnacks/sites/ns"  xmlns:sm="http://www.sitemaps.org/schemas/sitemap/0.9">     <site>         <name>weekend fun snacks</name>         <totalpages>127</totalpages>         <sm:urlset>             <sm:url>                 <sm:loc>http://example.com/weekendfunsnacks/?cat=58</sm:loc>             </sm:url>             <sm:url>                 <sm:loc>http://example.com/weekendfunsnacks/?cat=2</sm:loc>                 <sm:lastmod>2017-12-29t06:03:34+00:00</sm:lastmod>             </sm:url>             <sm:url>                 <sm:loc>http://example.com/weekendfunsnacks/?cat=15</sm:loc>                 <sm:lastmod>2017-12-29t05:24:04+00:00</sm:lastmod>             </sm:url>             <sm:url>                 <sm:loc>http://example.com/weekendfunsnacks/?cat=93</sm:loc>             </sm:url>             <sm:url>                 <sm:loc>http://example.com/weekendfunsnacks/?cat=55</sm:loc>             </sm:url>         </sm:urlset>     </site>     <site>         <name>paleo snacks</name>         <totalpages>52</totalpages>         <sm:urlset>             <sm:url>                 <sm:loc>http://example.com/primalsnacks/?cat=6</sm:loc>             </sm:url>             <sm:url>                 <sm:loc>http://example.com/primalsnacks/?cat=18</sm:loc>                 <sm:lastmod>2017-09-19t17:13:19+00:00</sm:lastmod>             </sm:url>             <sm:url>                 <sm:loc>http://example.com/primalsnacks/?cat=54</sm:loc>                 <sm:lastmod>2017-09-19t15:24:01+00:00</sm:lastmod>             </sm:url>             <sm:url>                 <sm:loc>http://example.com/primalsnacks/?cat=52</sm:loc>                 <sm:lastmod>2017-09-28t21:03:11+00:00</sm:lastmod>             </sm:url>             <sm:url>                 <sm:loc>http://example.com/primalsnacks/?cat=201</sm:loc>                 <sm:lastmod>2017-10-06t07:03:26+00:00</sm:lastmod>             </sm:url>             <sm:url>                 <sm:loc>http://example.com/primalsnacks/?cat=11</sm:loc>             </sm:url>         </sm:urlset>     </site>     <site>         <name>veg snacks</name>         <totalpages>17</totalpages>         <sm:urlset>             <sm:url>                 <sm:loc>http://example.com/vegsnacks/?cat=102</sm:loc>             </sm:url>             <sm:url>                 <sm:loc>http://example.com/vegsnacks/?cat=23</sm:loc>             </sm:url>             <sm:url>                 <sm:loc>http://example.com/vegsnacks/?cat=1</sm:loc>             </sm:url>             <sm:url>                 <sm:loc>http://example.com/vegsnacks/?cat=55</sm:loc>                 <sm:lastmod>2017-06-12t08:05:32+00:00</sm:lastmod>             </sm:url>             <sm:url>                 <sm:loc>http://example.com/vegsnacks/?cat=201</sm:loc>             </sm:url>             <sm:url>                 <sm:loc>http://example.com/vegsnacks/?cat=87</sm:loc>             </sm:url>         </sm:urlset>     </site> </sites> 

another possibility change default namespace on <urlset> required (although in opinion clearer use prefixes can explicitely know namespace working), this:

    <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">         <url>             <loc>http://example.com/weekendfunsnacks/?cat=2</loc>             <lastmod>2017-12-29t06:03:34+00:00</lastmod>         </url>         <!-- , on -->     </urlset> 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -