gpt4 book ai didi

xml - XSD 属性 NILLABLE 不起作用

转载 作者:数据小太阳 更新时间:2023-10-29 01:43:01 29 4
gpt4 key购买 nike

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

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

我认为发生此错误是因为我在该字段中有一个空字符,显示如下:
/HarvPop>

因此,为了解决这个问题,我尝试对元素使用 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

nillable 属性是这样使用的:

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

用法: <shipDate xsi:nil="true"></shipDate>

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

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

关于xml - XSD 属性 NILLABLE 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6831428/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com