具有数据类型的XML模式

时间:2013-07-23 08:32:31

标签: xml

我有一个带有数据的XML文档

  <?xml version="1.0" encoding="ISO-8859-1"?>

    <!-- Edited by XMLSpy® -->

    <bookstore>

        <book category="COOKING">

            <title lang="en">Everyday Italian</title>

            <author>Giada De Laurentiis</author>

            <year>2005</year>

            <price>30.00</price>

        </book>

        <book category="CHILDREN">

            <title lang="en">Harry Potter</title>

            <author>J K. Rowling</author>

            <year>2005</year>

            <price>29.99</price>

        </book>

        <book category="WEB">

            <title lang="en">XQuery Kick Start</title>

            <author>James McGovern</author>

            <author>Per Bothner</author>

            <author>Kurt Cagle</author>

            <author>James Linn</author>

            <author>Vaidyanathan Nagarajan</author>

            <year>2005</year>

            <price>49.99</price>

        </book>

        <book category="WEB">

            <title lang="en">Learning XML</title>

            <author>Erik T. Ray</author>

            <year>2005</year>

            <price>39.95</price>

        </book>

 </bookstore>

我想将<price>数据类型设置为Integer。 请帮我解决问题。

1 个答案:

答案 0 :(得分:0)

您可以使用在线工具生成架构。

http://www.freeformatter.com/xsd-generator.html#ad-output

<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="bookstore">
    <xs:annotation>
      <xs:documentation>Edited by XMLSpy®</xs:documentation>
    </xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="book" maxOccurs="unbounded" minOccurs="0">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="title">
                <xs:complexType>
                  <xs:simpleContent>
                    <xs:extension base="xs:string">
                      <xs:attribute type="xs:string" name="lang" use="optional"/>
                    </xs:extension>
                  </xs:simpleContent>
                </xs:complexType>
              </xs:element>
              <xs:element type="xs:string" name="author" maxOccurs="unbounded" minOccurs="0"/>
              <xs:element type="xs:short" name="year"/>
              <xs:element type="xs:float" name="price"/>
            </xs:sequence>
            <xs:attribute type="xs:string" name="category" use="optional"/>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>