XSD 属性 NILLABLE 不起作用

2024-04-26

我正在努力获取一个 xml 文件来根据 XSD 架构进行验证,但我在验证时遇到了问题。每次我验证时都会收到错误消息

“架构有效性错误:元素 '{http://services.website.com/ProgramResponse}Population': '' 不是原子类型 'xs:double' 的有效值。”

我相信发生此错误是因为该字段中有一个空字符,显示如下:

因此,为了解决这个问题,我尝试对元素使用 nillable="true" 属性,这样它们就可以为空,但仍然显示为空。这似乎是唯一的解决方案,但根本不起作用。我仍然收到错误。

我目前正在使用 XMLMate 进行验证,并且我还对几个在线验证器进行了双重检查。错误仍然存​​在。任何建议都会很棒。

<?xml version="1.0" encoding="UTF-8"?>
<xsd:element name="Reports" type="tns:ReportsType"/>

<xsd:complexType name="ReportsType">
    <xsd:sequence>
        <xsd:element name="Report" type="tns:ReportType" maxOccurs="unbounded" minOccurs="0"/>
    </xsd:sequence>
</xsd:complexType>

<xsd:complexType name="ReportType">
    <xsd:sequence>
        <xsd:element name="Id" nillable="true"/>
        <xsd:element name="Brand" type="xsd:string"/>
        <xsd:element name="Address" type="xsd:string"/>
        <xsd:element name="City" type="xsd:string"/>
        <xsd:element name="State" type="xsd:string"/>
        <xsd:element name="ZipCode" type="xsd:string"/>
        <xsd:element name="Entry" type="tns:EntryType" maxOccurs="unbounded" minOccurs="1"/>
    </xsd:sequence>
</xsd:complexType>

<xsd:complexType name="EntryType">
    <xsd:sequence>
        <xsd:element name="RM" nillable="true" type="xsd:double"/>
        <xsd:element name="Pop" nillable="true" type="xsd:double"/>
        <xsd:element name="Wt" nillable="true" type="xsd:double"/>
        <xsd:element name="EntryId" type="xsd:int"/>
    </xsd:sequence>
</xsd:complexType>

像这样的节点< HarvPop>< /HarvPop>表示该值存在并且它的值是一个空字符串。

根据此 w3.org 页面上的信息:http://www.w3.org/TR/xmlschema-0/#Nils http://www.w3.org/TR/xmlschema-0/#Nils

nillable 属性的使用方式如下:

定义:<xsd:element name="shipDate" type="xsd:date" nillable="true"/>

Usage: <shipDate xsi:nil="true"></shipDate>

即您必须明确声明该值为空。

另一种方法是声明 minoccurrs = 0,以允许该值缺失。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

XSD 属性 NILLABLE 不起作用 的相关文章

随机推荐