繁体   English   中英

使用XML进行模式验证(元素和属性)

[英]Schema validation with XML (element and attribute)

  <?xml version="1.0"?>
  <catalog xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
       xmlns:x="urn:book"> 
  <!-- START OF SCHEMA -->
  <xsd:schema targetNamespace="urn:book">
   <xsd:element name="book">
  <xsd:complexType>
    <xsd:sequence>
      <xsd:element name="author" type="xsd:string"/>
      <xsd:element name="title" type="xsd:string"/>
      <xsd:element name="genre" type="xsd:string"/>
      <xsd:element name="price" type="xsd:float"/>
      <xsd:element name="publish_date" type="xsd:date"/>
      <xsd:element name="description" type="xsd:string"/>
    </xsd:sequence>
    <xsd:attribute name="id" type="xsd:string"/>

  </xsd:complexType>
 </xsd:element>
</xsd:schema>
<!-- END OF SCHEMA -->
   <x:book id="bk101">
      <author>Gambardella, Matthew</author>
      <title>XML Developer's Guide</title>
      <genre>Computer</genre>
      <price currency="USD">44.95</price>
      <publish_date>2000-10-01</publish_date>
      <description lan="ENG">An in-depth look at creating applications with
      XML.</description>
   </x:book>
</catalog>

嗨,有人会介意在价格和说明元素中声明属性吗? 提前致谢

      <xsd:element name="description">
        <xsd:attribute name="gender">
          <xsd:simpleType>
            <xsd:restriction base="xs:string">
              <xsd:pattern value="male|female"/>
            </xsd:restriction>
          </xsd:simpleType>
        </xsd:attribute>
      </xsd:element>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM