美文网首页
XSD语法解析

XSD语法解析

作者: Oitavo_Liao | 来源:发表于2018-07-12 11:22 被阅读0次

    • xs:schema

    Xml Schema的根元素,类似于HTML中的<html>标签,只出现一次。

    • 属性

    <xs:schema xmlns="" -------表示此文档的默认命名空间
    xmlns:xs="http://www.w3.org/2001/XMLSchema"-------表示数据类型等定义的来源,在我们这里就是来自w3
    elementFormDefault="qualified">------表示要求xml文档的每一个元素都要有命名空间指定
    ……定义主体部分……
    </xs:schema>


    • xs:annotation

    xs:annotation,注释,出现此标签代表此处是一个注释,常与<xs:documentation>搭配使用,里面为注释内容。


    • xs:import

    <xs:import>使得可以在当前的文档中使用其他文档中指定的命名空间中的定义元素

    • 属性
    • namespace
      引用的命名空间
    • schemaLocation
      被引用命名空间的文档
    • <xs:import namespace="http://www.travelport.com/schema/common_v45_0" schemaLocation="../common_v45_0/Common.xsd"/> 
      

    • xs:element

    element 元素定义一个元素。

    • 属性
    • name
      规定元素的名称。如果父元素是 schema 元素,则此属性是必需的。
    • ref
      对另一个元素的引用。ref 属性可包含一个命名空间前缀。如果父元素是 schema 元素,则不是使用该属性。
      一般引用<xs:attribute>所定义的元素
    • type
      规定内建数据类型的名称
    • minOccurs
      规定 element 元素在父元素中可出现的最小次数。该值可以是大于或等于零的整数。默认值为 1
    • maxOccurs
      规定 element 元素在父元素中可出现的最大次数。该值可以是大于或等于零的整数。若不想对最大次数设置任何限制,请使用字符串 "unbounded"。 默认值为 1。
    •  <xs:element ref="OptionalServices" minOccurs="0"/>
       <xs:element ref="common:SupplierLocator" minOccurs="0" maxOccurs="999"/>
      
    • <xs:attribute name="OptionalServicesIndicator" type="xs:boolean" use="optional">
      <xs:annotation>
      <xs:documentation>Indicates true if flight provides
      optional services.</xs:documentation>
      </xs:annotation>
      </xs:attribute>
    • xs:attribute

    attribute 元素定义一个属性。

    • <xs:attribute name="OptionalServicesIndicator" type="xs:boolean" use="optional">
            <xs:annotation>
                <xs:documentation>Indicates true if flight provides
                      optional services.</xs:documentation>
            </xs:annotation>
        </xs:attribute>
      
    • name
      规定属性的名称。name 和 ref 属性不能同时出现。
    • ref
      规定对指定的属性的引用。name 和 ref 属性不能同时出现。如果 ref 出现,则 simpleType 元素、form 和 type 不能出现。
    • type
      规定内建的数据类型或简单类型。type 属性只能在内容不包含 simpleType 元素时出现。
    • use
      规定如何使用该属性。可设置下面的值:
      optional - 属性是可选的并且可以具有任何值(默认)。
      prohibited - 不能使用属性。
      required - 属性的必需的。
    • xs:complexType

    complexType 元素定义复杂类型。复杂类型的元素是包含其他元素和/或属性的 XML 元素。

    • 属性
    • name
      规定元素的名称。
    • 示例
    •  <xs:element name="AirReservation">
            <xs:annotation>
                <xs:documentation>The parent container for all booking data</xs:documentation>
            </xs:annotation>
            <xs:complexType>
                <xs:complexContent>//扩展标签
                    <xs:extension base="typeBaseAirReservation"/>//扩展内容
                </xs:complexContent>
            </xs:complexType>
        </xs:element>
      
    • 如上代码,定义了一个元素为"AirReservation",相当于一个类,name为类名,由另一个复杂类型 "typeBaseAirReservation" 对其进行扩展,typeBaseAirReservation相当于一个bean。
    • <xs:complexType name="typeBaseAirReservation">
        <xs:annotation>
            <xs:documentation>Parent Container for Air Reservation</xs:documentation>
        </xs:annotation>
        <xs:complexContent>
            <xs:extension base="common:BaseReservation">
                <xs:sequence>//元素要求组中的元素以指定的顺序出现在包含元素中
                    <xs:element ref="OptionalServices" minOccurs="0"/>
                    <xs:element ref="common:SupplierLocator" minOccurs="0" maxOccurs="999"/>
                    <xs:element ref="common:ThirdPartyInformation" minOccurs="0" maxOccurs="999"/>
                    <xs:element ref="DocumentInfo" minOccurs="0"/>
                    <xs:element ref="common:BookingTravelerRef" minOccurs="0" maxOccurs="999"/>
                    <xs:element ref="common:ProviderReservationInfoRef" minOccurs="0" maxOccurs="999"/>
                    <xs:element ref="AirSegment" minOccurs="0" maxOccurs="999"/>
                    <xs:element ref="SvcSegment" minOccurs="0" maxOccurs="999">
                        <xs:annotation>
                            <xs:documentation>Service segment added to collect additional fee. 1P only</xs:documentation>
                        </xs:annotation>
                    </xs:element>
                    <xs:element ref="AirPricingInfo" minOccurs="0" maxOccurs="999"/>
                    <xs:element ref="common:Payment" minOccurs="0" maxOccurs="999"/>
                    <xs:element ref="common:CreditCardAuth" minOccurs="0" maxOccurs="999"/>
                    <xs:element ref="FareNote" minOccurs="0" maxOccurs="999"/>
                    <xs:element ref="FeeInfo" minOccurs="0" maxOccurs="999"/>
                    <xs:element name="TaxInfo" type="typeTaxInfoWithPaymentRef" minOccurs="0" maxOccurs="999">
                        <xs:annotation>
                            <xs:documentation>Itinerary level taxes</xs:documentation>
                        </xs:annotation>
                    </xs:element>
                    <xs:element ref="TicketingModifiers" minOccurs="0" maxOccurs="999"/>
                    <xs:element ref="AssociatedRemark" minOccurs="0" maxOccurs="999"/>
                    <xs:element ref="PocketItineraryRemark" minOccurs="0" maxOccurs="999"/>
                    <xs:element ref="AirExchangeBundleTotal" minOccurs="0" maxOccurs="1"/>
                    <xs:element ref="AirExchangeBundle" minOccurs="0" maxOccurs="999">
                        <xs:annotation>
                            <xs:documentation>Bundle exchange, pricing, and penalty information. Providers ACH/1G/1V/1P</xs:documentation>
                        </xs:annotation>
                    </xs:element>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
        </xs:complexType>
      
    • 如上代码,就是一个复杂类型,一个element代表一个元素,ref为该元素的引用,minOccurs为该元素允许出现的最小次数,maxOccurs为允许出现的最大次数,ref中内容通常为一个xs:attribute,也就是一个属性。

    相关文章

      网友评论

          本文标题:XSD语法解析

          本文链接:https://www.haomeiwen.com/subject/pyrlpftx.html