2
votes

When uploading on a validator site the following errors are displayed : 1) s4s-elt-must-match.1: The content of 'pizza' must match (annotation?, (simpleType | complexType)?, (unique | key | keyref)*)). A problem was found starting at: complexType. 2)cvc-complex-type.2.4.a: Invalid content was found starting with element 'name'. One of '{pizza}' is expected.

Code is as follows: XML:

<?xml version="1.0"?>
<pizzamenu xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:noNamespaceSchemaLocation="schemasnippet.xsd"> 
   <pizza id = "0011"/>   
  <name> Tal Fenek </name>
  <price>  9.95 </price> 
<description>The application of Web protocols to Biology</description> 

</pizzamenu>

Schema:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="pizzamenu">
  <xs:complexType>
    <xs:sequence maxOccurs="unbounded">
      <xs:element name="pizza">
        <xs:complexType>
                <xs:attribute name="id" type="xs:string" />

              </xs:complexType>
        <xs:complexType>
          <xs:sequence>
            <xs:element name="name">

            </xs:element> <!-- name -->
            <xs:element name="price">

            </xs:element> <!-- price -->
            <xs:element name="description">
            </xs:element> <!-- description -->
          </xs:sequence>
        </xs:complexType>
      </xs:element> <!-- pizza -->
    </xs:sequence>
  </xs:complexType>
</xs:element> <!-- pizzamenu -->
</xs:schema>

Please help

1

1 Answers

2
votes

You seem to have problems in both your schema and your xml.

Your schema appears to be trying to specify that the name, price and description tags must be contained inside the pizza tag. In your xml, they are not.

Most likely the xml should be something more like:

<?xml version="1.0"?>
<pizzamenu xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:noNamespaceSchemaLocation="schemasnippet.xsd"> 
   <pizza id = "0011">   
      <name> Tal Fenek </name>
      <price>  9.95 </price> 
      <description>The application of Web protocols to Biology</description> 
   </pizza>
</pizzamenu>

But your schema is using two <xs:complexType> tags to define a single type, which doesn't work. A single <xs:complexType> can be used to define both the attributes and contents of your <pizza> tag as long as the attributes are put last. This means your schema should look like:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="pizzamenu">
        <xs:complexType >
            <xs:sequence maxOccurs="unbounded">
                <xs:element name="pizza">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="name">

                            </xs:element> <!-- name -->
                            <xs:element name="price">

                            </xs:element> <!-- price -->
                            <xs:element name="description">
                            </xs:element> <!-- description -->
                        </xs:sequence>
                        <xs:attribute name="id" type="xs:string" />
                    </xs:complexType>
                </xs:element> <!-- pizza -->
            </xs:sequence>
        </xs:complexType>
    </xs:element> <!-- pizzamenu -->
</xs:schema>