views:

606

answers:

3

I'm putting together an xml schema for a simple xml (see bellow for both xml and schema). But I keep getting the following error with regards to the section node: "The element cannot contain white space. Content model is empty." . Browsing the net I could not find any concise explanation as to what it means so I can fix it. Can anyone help?

Edit: thanks for all for offering help with the schema. I think it would help to have a concise description of what content model is and why it is empty here.

XML:

<config>
   <section name="facets">
      <facet type="format" label="Format" max="4"/>
      <facet type="language" max="4"/>
      <facet type="pubdate" max="6" submax="8"/> 
      <facet type="ice_topic" label="Fiction: Topic"/>
   </section>
</config>

Schema:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
   <xs:element name="config">
      <xs:complexType>
         <xs:sequence>
            <xs:element name="section" type="sectionBase"/>
         </xs:sequence>
      </xs:complexType>
   </xs:element>
   <xs:complexType name="sectionBase">
      <xs:attribute name="name" type="xs:ID"/>
   </xs:complexType>


   <xs:complexType name="sectionFacets" >
      <xs:complexContent>
         <xs:extension base="sectionBase">
            <xs:sequence>
               <xs:element name="facet" type="sectionFacetsBaseFacet"/>
            </xs:sequence>
         </xs:extension>
      </xs:complexContent>
   </xs:complexType>
   <xs:complexType name="sectionFacetsBaseFacet">
      <xs:attribute name="label" type="xs:ID"/>
      <xs:attribute name="max" type="xs:positiveInteger"/>
   </xs:complexType>
   <xs:complexType name="sectionFacetsFormat">
      <xs:complexContent>
         <xs:extension base="sectionFacetsBaseFacet"/>
      </xs:complexContent>
   </xs:complexType>
   <xs:complexType name="sectionFacetsPubdate">
      <xs:complexContent>
         <xs:extension base="sectionFacetsBaseFacet">
            <xs:attribute name="submax" type="xs:positiveInteger"/>
         </xs:extension>
      </xs:complexContent>

   </xs:complexType>
</xs:schema>
A: 

Your section element is defined as type sectionBase, and the sectionBase type definition only defines a single attribute. There's no reference anywhere in the schema to the sectionFacets type, which is probably what you need.

Try changing the type of the section element to sectionFacets

skaffman
ok - that would work, but I prepared the base type sectionBase to allow multiple section type, of which there is now only one - sectionFacets. What suggest would not allow it.
Boaz
Sounds like you need a substitution group
skaffman
+2  A: 

The label attribute of facet is set to xs:ID and this doesn't allow spaces. You might want to use xs:string instead.

Workshop Alex
Alex, I accept your answer because it's correct. I still would like to understand what the content model part means. Any idea?
Boaz
Reading material about Content models: http://www.stylusstudio.com/w3c/schema0/groups.htm
Workshop Alex
+1  A: 

There are several problem in our schema as others have already mentioned. Try something like this:

The extensible schema:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
    <!-- never used; just to be extended -->
    <xs:complexType name="sectionBaseType" abstract="true">
     <xs:attribute name="name" type="xs:ID"/>
    </xs:complexType>

    <!-- extension of the sectionBaseType -->
    <xs:complexType name="sectionSpecialized">
     <xs:complexContent>
      <xs:extension base="sectionBaseType">
       <xs:sequence>
        <xs:element name="facet" type="leftToTheReaderType"
         maxOccurs="unbounded"/>
       </xs:sequence>
      </xs:extension>
     </xs:complexContent>
    </xs:complexType>

    <!-- config may contain a single section or one of its extensions -->
    <xs:complexType name="configType">
     <xs:sequence>
      <xs:element name="section" type="sectionBaseType"/>
     </xs:sequence>
    </xs:complexType>

    <!-- a single root node called "config" -->
    <xs:element name="config" type="configType"/>
</xs:schema>

How to use the schema:

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
    <!-- note the xsi:type to specify the actual type of the section!! -->
    <section name="facets"
     xsi:type="sectionSpecialized">
     <facet .../>
     <facet .../>
     <facet .../> 
     <facet .../>
    </section>
</config>
janko
Thanks janko. Ideally I would avoid setting the type in the xml, as the point of the schema is to validate an xml/give structure it. I don't want to have a two-way dependency between the two.
Boaz