Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 没有内容的元素类型(长)_Xml_Wsdl_Xsd_Xsd Validation - Fatal编程技术网

Xml 没有内容的元素类型(长)

Xml 没有内容的元素类型(长),xml,wsdl,xsd,xsd-validation,Xml,Wsdl,Xsd,Xsd Validation,我的模式是: <xsd:element name="SetMonitor"> <xsd:complexType> <xsd:sequence> <xsd:element name="period" type="xsd:long" /> <xsd:element name="refreshrate" type="xsd:long" /> </x

我的模式是:

 <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>
如何修改wsdl,使其同时接受案例1案例2
请帮助。

您可以这样做:

    <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

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

2147483647
或者您可以使用模式修改元素的类型,类似这样

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

(模式的定义必须比我在本例中使用的更精确)

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

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

然后将元素定义为xsd:long和emptyString类型的并集

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


我试图修改上面提到的wsdl(顶部的那个)。但是我遇到了一个新问题,类似于由以下原因引起的
:org.xml.sax.SAXException:cvc complex type.2.4.b:元素“cb:SetMonitor”的内容不完整。“{”之一http://schemas.cordys.com/1.0/coboc“:period}”应为空。org.xml.sax.SAXParseException;行号:4;列数:3;cvc复杂类型.2.4.b:元素“cb:SetMonitor”的内容不完整。“{”之一http://schemas.cordys.com/1.0/coboc“:period}”是预期值。
如果我为period和refreshrate设置moiOccurs='0',则它可以工作。这意味着来自xml的
没有映射
minOccurs=“0”
表示可选元素(可以省略)
nillable=“true”
表示仍然需要xml中的元素,但您可以将其标记为
xsi:nil=“true”
(在其他语言中类似“null”的内容)我明白了您的观点,并感谢您的答复。但我正面临上述问题,并提出了解决方案。您能举一个xml导致上述问题的例子吗?
<xsd:element name="period">
    <xsd:simpleType>
        <xsd:restriction base="xsd:string">
            <xsd:pattern value="|([1-9][0-9]*)" />
        </xsd:restriction>
    </xsd:simpleType>
</xsd:element>
<xsd:simpleType name="emptyString">
    <xsd:restriction base="xsd:string">
        <xsd:length value="0"/>
    </xsd:restriction>
</xsd:simpleType>
<xsd:element name="period">
    <xsd:simpleType>
        <xsd:union memberTypes="xsd:long emptyString"/>
    </xsd:simpleType>
</xsd:element>