简单XML商品列表的XML模式

时间:2009-05-05 15:35:53

标签: xml xsd

我正在尝试编写一个验证以下XML的模式:

<category type="rifles">
  <item>
 <name>
   AK47
     </name>
 <description>
   The USSR's chief export back in the day, and the guerrilla's best friend. On African flags than any other symbol.
  </description>
  <cost>
    4000
  </cost>
  <image>
    ak47.jpg
  </image>
  <provenance>
    The USSR.
  </provenance>
  <quantity>
    10000
  </quantity>
</item>

(省略其他项目元素,剩余标题标签和结束标签。)

开发了以下架构:

<element name="store">
  <complexType>
 <sequence>
    <element name="category" maxOccurs="unbounded" >
      <complexType>
     <simpleContent>
        <extension base="string">
           <attribute name="type" type="string" />
        </extension>
      </simpleContent>
      <sequence>
        <element name="item" maxOccurs="unbounded" >
           <complexType>
          <sequence>
             <element name="name" type="string"/>
             <element name="description" type="string"/>
             <element name="image" type="string"/>
             <element name="cost" type="number"/>
             <element name="provenence" type="string"/>
             <element name="quantity" type="number"/>
           </sequence>
         </complexType>
           </element>
       </sequence>
     </complexType>
       </element>
     </sequence>
  </complexType>
</element>

http://www.xmlme.com/Validator.aspx?mid=83使用验证器,我得到:

架构错误:System.Xml.Schema.XmlSchemaException:复杂类型的内容模型必须包含“注释”(如果存在);然后是零或以下之一:'simpleContent','complexContent','group','choice','sequence'或'all';后跟零个或多个'attribute'或'attributeGroup';然后是零或一个'anyAttribute'。

我知道这可能听起来很傻,但任何人都可以指出我的错误吗?

1 个答案:

答案 0 :(得分:3)

尝试

<?xml version="1.0" encoding="utf-8" ?>
<!--Created with Liquid XML Studio - Developer Pro Edition 7.1.0.1135 (http://www.liquid-technologies.com)-->
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="category">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="0" maxOccurs="unbounded" name="item">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="name" type="xs:string" />
              <xs:element name="description" type="xs:string" />
              <xs:element name="cost" type="xs:unsignedShort" />
              <xs:element name="image" type="xs:string" />
              <xs:element name="provenance" type="xs:string" />
              <xs:element name="quantity" type="xs:unsignedShort" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
      <xs:attribute name="type" type="xs:string" use="required" />
    </xs:complexType>
  </xs:element>
</xs:schema>