欢迎光临
我们一直在努力

soap规范(5)-JSP教程,资料/其它

建站超值云服务器,限时71元/月

下例是一个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体元素的任意子元素中。这个属性没有缺省值。

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » soap规范(5)-JSP教程,资料/其它
分享到: 更多 (0)