我定义为SOAP请求XSD模式被发送给接受这样的请求的Web服务:我应该如何定义我的XSD以将动态类型用作元素?
<generic.GenericObject.configureInstanceWithResult xmlns="xmlapi_1.0">
[..]
<configInfo>
<lte.Cell>
<actionMask>
<bit>modify</bit>
</actionMask>
<spare1>1</spare1>
</lte.Cell>
</configInfo>
</generic.GenericObject.configureInstanceWithResult>
<generic.GenericObject.configureInstanceWithResult xmlns="xmlapi_1.0">
[...]
<configInfo>
<lte.LteNeighboringCellRelation>
<actionMask>
<bit>modify</bit>
</actionMask>
<cellIndividualOffset>-1</cellIndividualOffset>
</lte.LteNeighboringCellRelation>
</configInfo>
</generic.GenericObject.configureInstanceWithResult>
为了实现这个结果,我试图用这个模式定义:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="xmlapi_1.0" xmlns:tns="xmlapi_1.0" elementFormDefault="qualified">
<complexType name="Generic.GenericObject.configureInstanceWithResult">
<sequence>
[...]
<element name="configInfo" type="tns:ConfigInfo" />
</sequence>
</complexType>
<complexType name="ConfigInfo">
<sequence>
<element name="payload" type="anyType" />
</sequence>
</complexType>
<complexType name="lte.Cell">
<sequence>
<element name="spare" type="string" />
</sequence>
</complexType>
<complexType name="lte.LteNeighboringCellRelation">
<sequence>
<element name="qOffsetCell" type="string" />
<element name="cellIndividualOffset" type="string" />
</sequence>
</complexType>
<element name="generic.GenericObject.configureInstanceWithResult" type="tns:Generic.GenericObject.configureInstanceWithResult" />
但结果我得到的是这样一个:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<generic.GenericObject.configureInstanceWithResult xmlns="xmlapi_1.0">
<configInfo>
<payload xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="lte.Cell">
<spare>-1</spare>
</payload>
</configInfo>
</generic.GenericObject.configureInstanceWithResult>
您是否看到过我可以用xsi:type="lte.Cell"
作为<lte.Cell>
而不是<payload>
?
注意:在ConfigInfo中使用anyType
不好,因为<configInfo>
被删除,请求不再符合要求。
谢谢迈克尔。我正在考虑这个选项,但问题是你必须指定被用作“有效载荷”的对象的类型。这里的问题是,这个对象是配置大量不同类型的“API”的基础,所以如果我们做一些真正动态的事情(没有任何硬编码)会更好。我目前正在尝试使用“xs:any”的解决方案,并使用@XMLRootElement标记每个元素,我认为它们能正常工作。 – Victor 2014-09-11 14:19:55