元素类型(long) 无内容 [英] Element type(long) without content

查看:20
本文介绍了元素类型(long) 无内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的架构是:

 <xsd:element name="SetMonitor">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element name="period" type="xsd:long" />
            <xsd:element name="refreshrate" type="xsd:long" />
        </xsd:sequence>
    </xsd:complexType>
</xsd:element>

我的 xml 将是:

案例 1.

<SetMonitor
    xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:cb="http://schemas.cordys.com/1.0/coboc">
    <period/>
    <refreshrate/>
</SetMonitor>

案例 2.

 <SetMonitor
        xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/"
        xmlns:cb="http://schemas.cordys.com/1.0/coboc">
        <period>10</period>
        <refreshrate>20</refreshrate>
    </SetMonitor>

对于情况 2,没有问题.但是对于情况 1,我收到以下错误:

For case 2 there are no issues. But for case 1 I get the following error:

Caused by: org.xml.sax.SAXException: cvc-datatype-valid.1.2.1: '' is not a valid value for 'integer'.
org.xml.sax.SAXParseException; lineNumber: 6; columnNumber: 14; cvc-datatype-valid.1.2.1: '' is not a valid value for 'integer'.

如何修改 wsdl 以使其同时接受case 1case 2?请帮忙.

How can i modify the wsdl so that it accepts both case 1 and case 2? Please help.

推荐答案

你可以这样做:

    <xsd:element name="SetMonitor">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="period" type="xsd:long"  nillable="true"/>
                <xsd:element name="refreshrate" type="xsd:long" nillable="true"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>

并以这种方式构造带有空"元素的xml

And construct xml with "empty" element in this way

<SetMonitor xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <period>2147483647</period>
    <refreshrate xsi:nil="true" />
</SetMonitor>

或者你可以使用模式修改元素的类型,就像这样

Or you could modify the type of element using pattern, something like this

<xsd:element name="period">
    <xsd:simpleType>
        <xsd:restriction base="xsd:string">
            <xsd:pattern value="|([1-9][0-9]*)" />
        </xsd:restriction>
    </xsd:simpleType>
</xsd:element>

(必须更精确地定义模式,而不是我在此示例中使用的)

(the pattern has to be define more precisly, than I use for this example)

另一种可能是为空字符串定义 simpleType

Another possibility could be to define simpleType for empty string

<xsd:simpleType name="emptyString">
    <xsd:restriction base="xsd:string">
        <xsd:length value="0"/>
    </xsd:restriction>
</xsd:simpleType>

然后将您的元素定义为 xsd:long 和 emptyString 类型的联合

and then define your element as union of xsd:long and emptyString type

<xsd:element name="period">
    <xsd:simpleType>
        <xsd:union memberTypes="xsd:long emptyString"/>
    </xsd:simpleType>
</xsd:element>

这篇关于元素类型(long) 无内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆