📄 soap4.htm
字号:
<P><BR><enc:Array
xmlns:enc="http://www.w3.org/2001/06/soap-encoding"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
enc:ArrayType="xs:int[2]" > <enc:int>3</enc:int>
<enc:int>4</enc:int></enc:Array></P>
<P><BR>Using the enc:Array element</P>
<P><BR>数组可以包含任意指定arrayType的子类型的实例。也就是说,成员的类型可以是任何描述在arrayType属性中类型的可替代类型,这将依照于在模式中表示的可替代规则。因此,例如,一个整数数组可以包含任何源于integer的类型的值(例如
“int”或任何用户定义的源于integer的类型)。类似的,一个“address”数组可以包含一个严格的或扩展的类型,比如“internationalAddress”。因为提供的enc:Array类型允许包含任何类型或类型混合的成员,除非有对arrayType属性使用的特别限制。</P>
<P></P>
<P>成员元素类型在实例中可以使用xsi:type来描述,或则是在成员元素模式中声明,就象在下面两个数组中分别演示的那样:</P>
<P></P>
<P></P>
<P>Example 28</P>
<P><BR><enc:Array
xmlns:enc="http://www.w3.org/2001/06/soap-encoding"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
enc:arrayType="xs:anyType[4]"> <thing
xsi:type="xs:int">12345</thing> <thing
xsi:type="xs:decimal">6.789</thing> <thing
xsi:type="xs:string"> Of Mans First Disobedience, and the Fruit
Of that Forbidden Tree, whose mortal tast Brought Death into the
World, and all our woe, </thing> <thing
xsi:type="xs:anyURI">
http://www.dartmouth.edu/~milton/reading_room/
</thing></enc:Array></P>
<P><BR>Array with elements of varying types</P>
<P><BR> </P>
<P></P>
<P></P>
<P>Example 29</P>
<P><BR><enc:Array xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:enc="http://www.w3.org/2001/06/soap-encoding"
enc:arrayType="xs:anyType[4]" >
<enc:int>12345</enc:int>
<enc:decimal>6.789</enc:decimal> <enc:string> Of
Mans First Disobedience, and the Fruit Of that Forbidden Tree, whose
mortal tast Brought Death into the World, and all our woe,
</enc:string> <enc:anyURI>
http://www.dartmouth.edu/~milton/reading_room/ </enc:anyURI
></enc:Array></P>
<P><BR>Array with elements of varying types</P>
<P><BR>数组值可以是结构或其他复合值。例如一个“xyz:Order”结构的数组:</P>
<P></P>
<P></P>
<P>Example 30</P>
<P><BR><enc:Array
xmlns:enc="http://www.w3.org/2001/06/soap-encoding"
xmlns:xyz="http://example.org/2001/06/Orders"
enc:arrayType="xyz:Order[2]"> <Order>
<Product>Apple</Product> <Price>1.56</Price>
</Order> <Order> <Product>Peach</Product>
<Price>1.48</Price> </Order></enc:Array></P>
<P><BR>Arrays containing structs and other compound values</P>
<P><BR>数组也可以有一些成员值是数组。下面是一个有两个数组的数组的例子,而那两个数组都是string数组:</P>
<P></P>
<P></P>
<P>Example 31</P>
<P><BR><enc:Array xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:enc="http://www.w3.org/2001/06/soap-encoding"
enc:arrayType="xs:string[][2]" > <item href="#array-1"/>
<item href="#array-2"/></enc:Array><enc:Array
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:enc="http://www.w3.org/2001/06/soap-encoding" id="array-1"
enc:arrayType="xs:string[2]"> <item>r1c1</item>
<item>r1c2</item>
<item>r1c3</item></enc:Array><enc:Array
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:enc="http://www.w3.org/2001/06/soap-encoding" id="array-2"
enc:arrayType="xs:string[2]"> <item>r2c1</item>
<item>r2c2</item></enc:Array></P>
<P><BR>Array containing other arrays</P>
<P><BR>包含一个数组值的元素并不需要一定被命名为“enc:Array”。它可以有任意的名,而提供的类型则要么是enc:Array,要么是受源于enc:Array的限制。例如,下面是一个模式片段以及与之一致的一个实例数组:</P>
<P></P>
<P></P>
<P>Example 32</P>
<P><BR><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:enc="http://www.w3.org/2001/06/soap-encoding"
xmlns:tns="http://example.org/2001/06/numbers"
targetNamespace="http://example.org/2001/06/numbers" >
<xs:simpleType name="phoneNumberType" > <xs:restriction
base="xs:string" /> </xs:simpleType> <xs:element
name="ArrayOfPhoneNumbers" type="tns:ArrayOfPhoneNumbersType" />
<xs:complexType name="ArrayOfPhoneNumbersType" >
<xs:complexContent> <xs:restriction base="enc:Array" >
<xs:sequence> <xs:element name="phoneNumber"
type="tns:phoneNumberType" maxOccurs="unbounded" />
</xs:sequence> <xs:attributeGroup ref="enc:arrayAttributes"
/> <xs:attributeGroup ref="enc:commonAttributes" />
</xs:restriction> </xs:complexContent>
</xs:complexType></xs:schema></P>
<P><BR>Schema for an array</P>
<P><BR> </P>
<P></P>
<P></P>
<P>Example 33</P>
<P><BR><abc:ArrayOfPhoneNumbers
xmlns:abc="http://example.org/2001/06/numbers"
xmlns:enc="http://www.w3.org/2001/06/soap-encoding"
enc:arrayType="abc:phoneNumberType[2]" >
<phoneNumber>206-555-1212</phoneNumber>
<phoneNumber>1-888-123-4567</phoneNumber></abc:ArrayOfPhoneNumbers></P>
<P><BR>Array conforming to the schema in Example 32</P>
<P><BR>数组可以是多维的。在这种情况下,就会有多个描述维数大小的值出现在arrayType属性的asize部分:</P>
<P></P>
<P></P>
<P>Example 34</P>
<P><BR><enc:Array xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:enc="http://www.w3.org/2001/06/soap-encoding"
enc:arrayType="xs:string[2,3]" > <item>r1c1</item>
<item>r1c2</item> <item>r1c3</item>
<item>r2c1</item> <item>r2c2</item>
<item>r2c3</item></enc:Array></P>
<P><BR>Multi-dimensonal array</P>
<P><BR>上述例子中显示了一个数组如何被编码为独立元素,数组值可以以嵌套方式出现并且如果他们是单引用的话,应该使用这种方式。</P>
<P></P>
<P>下面是一个模式片段的例子以及符合该模式的一个嵌套在“Person”结构中的电话号码数组,该数组可以从存取标识“phone-numbers”访问:</P>
<P></P>
<P></P>
<P>Example 34</P>
<P><BR><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:enc="http://www.w3.org/2001/06/soap-encoding"
xmlns:tns="http://example.org/2001/06/numbers"
targetNamespace="http://example.org/2001/06/numbers" >
<xs:import namespace="http://www.w3.org/2001/06/soap-encoding"
/> <xs:simpleType name="phoneNumberType" >
<xs:restriction base="xs:string" /> </xs:simpleType>
<xs:element name="ArrayOfPhoneNumbers"
type="tns:ArrayOfPhoneNumbersType" /> <xs:complexType
name="ArrayOfPhoneNumbersType" > <xs:complexContent>
<xs:restriction base="enc:Array" > <xs:sequence>
<xs:element name="phoneNumber" type="tns:phoneNumberType"
maxOccurs="unbounded" /> </xs:sequence>
<xs:attributeGroup ref="enc:arrayAttributes" />
<xs:attributeGroup ref="enc:commonAttributes" />
</xs:restriction> </xs:complexContent>
</xs:complexType> <xs:element name="Person">
<xs:complexType> <xs:sequence> <xs:element
name="name" type="xs:string" /> <xs:element
name="phoneNumbers" type="tns:ArrayOfPhoneNumbersType" />
</xs:sequence> </xs:complexType>
</xs:element></xs:schema></P>
<P><BR>Schema fragment for array of phone numbers embedded in a
struct</P>
<P><BR> </P>
<P></P>
<P></P>
<P>Example 35</P>
<P><BR><def:Person xmlns:def="http://example.org/2001/06/numbers"
xmlns:enc="http://www.w3.org/2001/06/soap-encoding" >
<name>John Hancock</name> <phoneNumbers
enc:arrayType="def:phoneNumber[2]">
<phoneNumber>206-555-1212</phoneNumber>
<phoneNumber>1-888-123-4567</phoneNumber>
</phoneNumbers></def:Person></P>
<P><BR>Array of phone numbers embedded in a struct conforming to the
schema in Example 34</P>
<P><BR>下面是单引用数组值的另一个例子,数组值被编码为嵌入元素,这些元素都包含作为存取标识的元素名:</P>
<P></P>
<P></P>
<P>Example 36</P>
<P><BR><xyz:PurchaseOrder
xmlns:xyz="http://example.org/2001/06/Orders" >
<CustomerName>Henry Ford</CustomerName> <ShipTo>
<Street>5th Ave</Street> <City>New
York</City> <State>NY</State>
<Zip>10010</Zip> </ShipTo> <PurchaseLineItems
xmlns:enc="http://www.w3.org/2001/06/soap-encoding"
enc:arrayType="xyz:Order[2]"> <Order>
<Product>Apple</Product> <Price>1.56</Price>
</Order> <Order> <Product>Peach</Product>
<Price>1.48</Price> </Order>
</PurchaseLineItems></xyz:PurchaseOrder></P>
<P><BR>Single-reference array encoded as en embedded element</P>
<P><BR>5.4.2.1 部分传输数组</P>
<P><BR>SOAP提供对部分传递数组的支持,这就象在一些上下文[12]中的“可变长”数组。一个部分传递数组应使用“enc:offset”属性标识,该属性的记数是以第一元素的位移为0开始的。如果省略该属性,则位移默认是0。</P>
<P></P>
<P>下面是一个大小为5的数组,同时在传递的时候仅传递第三和第四个元素:</P>
<P></P>
<P></P>
<P>Example 37</P>
<P><BR><enc:Array
xmlns:enc="http://www.w3.org/2001/06/soap-encoding"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
enc:arrayType="xs:string[6]" enc:offset="[3]" > <item>The
fourth element</item> <item>The fifth
element</item></enc:Array></P>
<P><BR>Array of size five that transmits only the third and fourth
element</P>
<P><BR>5.4.2.2 稀疏数组</P>
<P><BR>SOAP提供对稀疏数组的支持。每一个表示成员值的元素包含一个“enc:position”属
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -