📄 soap协议规范.htm
字号:
<BR></e:Person></P></BLOCKQUOTE>
<P>序列化可以包含对不在同一个资源的值的引用:</P>
<BLOCKQUOTE>
<P><e:Book> <BR><title>Paradise Lost</title>
<BR><firstauthor href="http://www.dartmouth.edu/~milton/"/>
<BR></e:Book></P></BLOCKQUOTE>
<P>以下是描述上面结构的schema片断:</P>
<BLOCKQUOTE>
<P><element name="Book" type="tns:Book"/> <BR><complexType
name="Book"> <BR><!-- Either the following group must occur or
else the <BR>href attribute must appear, but not both. -->
<BR><sequence minOccurs="0" maxOccurs="1"> <BR><element
name="title" type="xsd:string"/> <BR><element name="firstauthor"
type="tns:Person"/> <BR><element name="secondauthor"
type="tns:Person"/> <BR></sequence> <BR><attribute
name="href" type="uriReference"/> <BR><attribute name="id"
type="ID"/> <BR><anyAttribute namespace="##other"/>
<BR></complexType> <BR><element name="Person"
base="tns:Person"/> <BR><complexType name="Person"> <BR><!--
Either the following group must occur or else the <BR>href attribute
must appear, but not both. --> <BR><sequence minOccurs="0"
maxOccurs="1"> <BR><element name="name" type="xsd:string"/>
<BR><element name="address" type="tns:Address"/>
<BR></sequence> <BR><attribute name="href"
type="uriReference"/> <BR><attribute name="id" type="ID"/>
<BR><anyAttribute namespace="##other"/> <BR></complexType>
<BR><element name="Address" base="tns:Address"/>
<BR><complexType name="Address"> <BR><!-- Either the following
group must occur or else the <BR>href attribute must appear, but not
both. --> <BR><sequence minOccurs="0" maxOccurs="1">
<BR><element name="street" type="xsd:string"/> <BR><element
name="city" type="xsd:string"/> <BR><element name="state"
type="xsd:string"/> <BR></sequence> <BR><attribute
name="href" type="uriReference"/> <BR><attribute name="id"
type="ID"/> <BR><anyAttribute namespace="##other"/>
<BR></complexType></P></BLOCKQUOTE>
<H4>5.4.2 数组</H4>
<P>SOAP数组定义为具有"SOAP-ENC:Array"类型或一个从"SOAP-ENC:Array"衍生的类型(参见规则8)。数组表示为元素值,对元素的名没有特别的约束(正如元素值并不约束它们所属的元素)。数组可以包含任意类型的元素,包括嵌套数组。可以创建新的类型(受SOAP-ENC:Array
<BR>类型限制)来表示数组,如整数数组或某些用户定义的枚举。数组值表示为组成这个数组的项的元素的规则序列。在数组值中,元素名对于区分accesor并不重要。元素可以有任意的名。实际上,元素常常用它们在schema中暗示或确定的数组类型来命名元素。并且一般情况下对于复合值来说,如果数组中数组项的值是single-reference值,则这个数组项包含它的值,否则,该数组项通过"href"属性引用这个值。下面的例子是一个整型数组的schema片断:</P>
<BLOCKQUOTE>
<P><element name="myFavoriteNumbers" <BR>type="SOAP-ENC:Array"/>
<BR><myFavoriteNumbers <BR>SOAP-ENC:arrayType="xsd:int[2]">
<BR><number>3</number> <BR><number>4</number>
<BR></myFavoriteNumbers></P></BLOCKQUOTE>
<P>在这个例子中,数组"myFavoriteNumbers"包括几个成员,每个成员是一个类型为SOAP-ENC:int的值。注意SOAP-ENC:Array允许不受限制的元素名,它们不传达任何类型信息,所以在使用时,或者它们有xsi:type属性,或者它们所属的元素有SOAP-ENC:arrayType属性。自然,由SOAP-ENC:Array衍生的类型可以声明局部元素,但这种情况下要包括类型信息。上面已经提到,SOAP-ENC
schema包含了元素的声明,元素名与"XML Schema Part 2:
Datatypes"规范[11]中的简单类型一致。其中包括了对"Array"的声明。于是,我们可以这样写:</P>
<BLOCKQUOTE>
<P><SOAP-ENC:Array SOAP-ENC:arrayType="xsd:int[2]">
<BR><SOAP-ENC:int>3</SOAP-ENC:int>
<BR><SOAP-ENC:int>4</SOAP-ENC:int>
<BR></SOAP-ENC:Array></P></BLOCKQUOTE>
<P>数组可以包含特定arrayType的任意子类型的实例。即,数组成员可以是arryType属性值指定的类型的任意子类型,这个类型对于arrayType属性中指定的类型来说是可替换的(根据schema中的替换规则)。例如,一个整型数组可以包含从整型衍生的任意类型(如"int"或任意用户定义的从整型衍生的类型)。同样,一个"address"数组可能包含一个address的受限类型或扩展类型如"internationalAddress"。因为提供的SOAP-ENC:Array类型允许任意类型的成员,所以可以包含任意类型的混合除非使用arrayType属性加以特别的限制。在实例中,可以使用xsi:type指定成员元素的类型,或通过schema中成员元素的声明来指定。下面是两个例子。</P>
<BLOCKQUOTE>
<P><SOAP-ENC:Array SOAP-ENC:arrayType="SOAP-ENC:ur-type[4]">
<BR><thing xsi:type="xsd:int">12345</thing> <BR><thing
xsi:type="xsd:decimal">6.789</thing> <BR><thing
xsi:type="xsd:string"> <BR>Of Mans First Disobedience, and the Fruit
<BR>Of that Forbidden Tree, whose mortal tast <BR>Brought Death into the
World, and all our woe, <BR></thing> <BR><thing
xsi:type="xsd:uriReference">
http://www.dartmouth.edu/~milton/reading_room/ </thing>
<BR></SOAP-ENC:Array> <BR><SOAP-ENC:Array
SOAP-ENC:arrayType="SOAP-ENC:ur-type[4]">
<BR><SOAP-ENC:int>12345</SOAP-ENC:int>
<BR><SOAP-ENC:decimal>6.789</SOAP-ENC:decimal>
<BR><xsd:string> <BR>Of Mans First Disobedience, and the Fruit
<BR>Of that Forbidden Tree, whose mortal tast <BR>Brought Death into the
World, and all our woe, <BR></xsd:string>
<BR><SOAP-ENC:uriReference>
http://www.dartmouth.edu/~milton/reading_room/
</SOAP-ENC:uriReference >
<BR></SOAP-ENC:Array></P></BLOCKQUOTE>
<P>数组值可以是结构或其它复合值。例如"xyz:Order"结构数组:</P>
<BLOCKQUOTE>
<P><SOAP-ENC:Array SOAP-ENC:arrayType="xyz:Order[2]">
<BR><Order> <BR><Product>Apple</Product>
<BR><Price>1.56</Price> <BR></Order> <BR><Order>
<BR><Product>Peach</Product>
<BR><Price>1.48</Price> <BR></Order>
<BR></SOAP-ENC:Array></P></BLOCKQUOTE>
<P>数组成员值也可以是数组。下例是两个字符串数组组成的数组:</P>
<BLOCKQUOTE>
<P><SOAP-ENC:Array SOAP-ENC:arrayType="xsd:string[][2]">
<BR><item href="#array-1"/> <BR><item href="#array-2"/>
<BR></SOAP-ENC:Array> <BR><SOAP-ENC:Array id="array-1"
SOAP-ENC:arrayType="xsd:string[2]"> <BR><item>r1c1</item>
<BR><item>r1c2</item> <BR><item>r1c3</item>
<BR></SOAP-ENC:Array> <BR><SOAP-ENC:Array id="array-2"
SOAP-ENC:arrayType="xsd:string[2]"> <BR><item>r2c1</item>
<BR><item>r2c2</item>
<BR></SOAP-ENC:Array></P></BLOCKQUOTE>
<P>包含数组的元素无需命名为"SOAP-ENC:Array"。它可以有任意的名,只要元素的类型是SOAP-ENC:Array或由之衍生的类型。例如,下面是一个schema片断和与之一致的数组实例。</P>
<BLOCKQUOTE>
<P><simpleType name="phoneNumber" base="string"/> <BR><element
name="ArrayOfPhoneNumbers"> <BR><complexType
base="SOAP-ENC:Array"> <BR><element name="phoneNumber"
type="tns:phoneNumber" maxOccurs="unbounded" />
<BR></complexType> <BR><anyAttribute/> <BR></element>
<BR><xyz:ArrayOfPhoneNumbers
SOAP-ENC:arrayType="xyz:phoneNumber[2]">
<BR><phoneNumber>206-555-1212</phoneNumber>
<BR><phoneNumber>1-888-123-4567</phoneNumber>
<BR></xyz:ArrayOfPhoneNumbers></P></BLOCKQUOTE>
<P>数组可能是多维的。在这种情况下,在arrayType属性的asize部分将不止有一个值:</P>
<BLOCKQUOTE>
<P><SOAP-ENC:Array SOAP-ENC:arrayType="xsd:string[2,3]">
<BR><item>r1c1</item> <BR><item>r1c2</item>
<BR><item>r1c3</item> <BR><item>r2c1</item>
<BR><item>r2c2</item> <BR><item>r2c3</item>
<BR></SOAP-ENC:Array></P></BLOCKQUOTE>
<P>虽然上面的例子把数组编码为独立的元素,但元素值也可以是嵌入形式,而且若元素值是single
reference时,必须编码为嵌入形式。下例是一个schema片断,电话号码数组嵌入到一个类型为"Person"的结构中,并且通过accessor
"phone-numbers"访问它:</P>
<BLOCKQUOTE>
<P><simpleType name="phoneNumber" base="string"/> <BR><element
name="ArrayOfPhoneNumbers"> <BR><complexType
base="SOAP-ENC:Array"> <BR><element name="phoneNumber"
type="tns:phoneNumber" maxOccurs="unbounded"/>
<BR></complexType> <BR><anyAttribute/> <BR></element>
<BR><element name="Person"> <BR><complexType>
<BR><element name="name" type="string"/> <BR><element
name="phoneNumbers" type="tns:ArrayOfPhoneNumbers"/>
<BR></complexType> <BR></element> <BR><xyz:Person>
<BR><name>John Hancock</name> <BR><phoneNumbers
SOAP-ENC:arrayType="xyz:phoneNumber[2]">
<BR><phoneNumber>206-555-1212</phoneNumber>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -