?? soap規范(5).txt
字號:
作者:bdsc
email: bdscca@yahoo.ca
日期:2001-7-13 17:07:24
下例是一個schema片斷,電話號碼數組嵌入到一個類型為"Person"的結構中,并且通過accessor "phone-numbers"訪問它:
<simpleType name="phoneNumber" base="string"/>
<element name="ArrayOfPhoneNumbers">
<complexType base="SOAP-ENC:Array">
<element name="phoneNumber" type="tns:phoneNumber" maxOccurs="unbounded"/>
</complexType>
<anyAttribute/>
</element>
<element name="Person">
<complexType>
<element name="name" type="string"/>
<element name="phoneNumbers" type="tns:ArrayOfPhoneNumbers"/>
</complexType>
</element>
<xyz:Person>
<name>John Hancock</name>
<phoneNumbers SOAP-ENC:arrayType="xyz:phoneNumber[2]">
<phoneNumber>206-555-1212</phoneNumber>
<phoneNumber>1-888-123-4567</phoneNumber>
</phoneNumbers>
</xyz:Person>
下面的例子中,數組值為single-reference,被編碼為嵌入元素,包含它的元素名即為入口名:
<xyz:PurchaseOrder>
<CustomerName>Henry Ford</CustomerName>
<ShipTo>
<Street>5th Ave</Street>
<City>New York</City>
<State>NY</State>
<Zip>10010</Zip>
</ShipTo>
<PurchaseLineItems SOAP-ENC:arrayType="Order[2]">
<Order>
<Product>Apple</Product>
<Price>1.56</Price>
</Order>
<Order>
<Product>Peach</Product>
<Price>1.48</Price>
</Order>
</PurchaseLineItems>
</xyz:PurchaseOrder>
5.4.2.1 部分儲值(partially transmitted)數組
SOAP提供了對部分儲值(partially transmitted)數組的支持,如某些上下文中的可變數組。一個partially transmitted 數組由一個"SOAP-ENC:offset"屬性(從第一個transmitted的元素開始的偏移量,基于0)指示。如果省略,偏移量取0。
下面的例子中數組的大小為5,但只有從0起,第三和第四個元素被儲值。
<SOAP-ENC:Array ;SOAP-ENC:arrayType="xsd:string[5]" ;SOAP-ENC:offset="[2]">
<item>The third element</item>
<item>The fourth element</item>
</SOAP-ENC:Array>
5.4.2.2 稀疏數組Sparse Arrays
SOAP提供了對稀疏數組的支持。每個表示成員值的元素包含一個"SOAP-ENC:position"屬性,用來指示它在數組中的位置。下例是兩維字符串稀疏數組的例子,數組大小是4,但只用到第2個。
<SOAP-ENC:Array SOAP-ENC:arrayType="xsd:string[,][4]">
<SOAP-ENC:Array href="#array-1" SOAP-ENC:position="[2]"/>
</SOAP-ENC:Array>
<SOAP-ENC:Array id="array-1" SOAP-ENC:arrayType="xsd:string[10,10]">
<item SOAP-ENC:position="[2,2]">Third row, third col</item>
<item SOAP-ENC:position="[7,2]">Eighth row, third col</item>
</SOAP-ENC:Array>
如果對array-1的引用僅發生在數組內部,上例也可以編碼如下:
<SOAP-ENC:Array SOAP-ENC:arrayType="xsd:string[,][4]">
<SOAP-ENC:Array SOAP-ENC:position="[2]" SOAP-ENC:arrayType="xsd:string[10,10]>
<item SOAP-ENC:position="[2,2]">Third row, third col</item>
<item SOAP-ENC:position="[7,2]">Eighth row, third col</item>
</SOAP-ENC:Array>
</SOAP-ENC:Array>
5.4.3 一般復合類型
在這里提到的編碼規則不僅僅限于accessor名已知的情況,如果accessor名是運行環境下實時獲得的,編碼規則同樣適用,也就是說accessor編碼成一個元素名與accessor名匹配的元素,同時accessor可能包含或者引用該元素的值。如果accessor包含類型不能事先確定的值,它必須包含一個合適的屬性xsi:type 。
類似地,上述引用的規則已經足夠用于復合類型的序列化,這些復合類型可能包含用名區分的accessors(結構)和用名及序數位置區分的accessors。(可能包含重復的accessor)實際上這并不要求任何schema模式包含這些類型,但更為準確的說法是:一個類型模型(type-model)schema如果有這些類型,就可以構造一個符合XML句法規則的schema和XML文檔實例。
<xyz:PurchaseOrder>
<CustomerName>Henry Ford</CustomerName>
<ShipTo>
<Street>5th Ave</Street>
<City>New York</City>
<State>NY</State>
<Zip>10010</Zip>
</ShipTo>
<PurchaseLineItems>
<Order>
<Product>Apple</Product>
<Price>1.56</Price>
</Order>
<Order>
<Product>Peach</Product>
<Price>1.48</Price>
</Order>
</PurchaseLineItems>
</xyz:PurchaseOrder>
類似地,將一個結構上類似數組但實際上不是一個 SOAP-ENC:Array類型或者 SOAP-ENC:Array子類型的復合值序列化同樣是允許的,例如:
<PurchaseLineItems>
<Order>
<Product>Apple</Product>
<Price>1.56</Price>
</Order>
<Order>
<Product>Peach</Product>
<Price>1.48</Price>
</Order>
</PurchaseLineItems>
5.5 缺省值
省略accessor元素意味著或者有一個缺省值或者值不知道。具體細節依靠這個accessor,方法和上下文。例如,對于多態accessor,省略accessor一般意味著一個Null值。同樣,省略布爾accessor一般意味著False值或者值不知道,省略數字accessor一般意味著值為零或者值不知道。
5.6 SOAP root屬性
SOAP root 屬性可用于標記一個序列化root,從而一個對象可以反序列化(deserialized),而實際上該root并不是真正的對象root。這個屬性有兩個可選值"1" or "0"。對象真正的roots屬性值為“1” ,序列化root但不是真正的root屬性值也為“1”,元素如果要顯式地指定不能為序列化root,只需將該屬性設置為“0” SOAP root屬性可以出現在SOAP頭和SOAP體元素的任意子元素中。(譯者注:SOAP root屬性為0的元素不是一個獨立的實體,外部的應用不能訪問到該元素,但該元素可以被SOAP文檔本身的其它元素訪問到)
SOAP root屬性可以出現在SOAP頭和SOAP體元素的任意子元素中。這個屬性沒有缺省值。
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -