XSD 属性 NILLABLE 不起作用 [英] XSD attribute NILLABLE not working

查看:21
本文介绍了XSD 属性 NILLABLE 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在获取一个 xml 文件以针对 XSD 架构进行验证,但我在验证时遇到了问题.每次我验证我都会收到错误说

I am working on getting an xml file to validate against an XSD schema and I'm having trouble with the validations. Every time I validate I get errors saying

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

"Schemas validity error: Element '{http://services.website.com/ProgramResponse}Population': '' is not a valid value of the atomic type 'xs:double'."

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

I believe this error happens because I have a null character in that field, displayed like this:
< HarvPop>< /HarvPop>

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

So, to solve this I tried using the nillable="true" attribute for the elements so they will be able to be null, but still show up as empty. This seems to be the only solution, but it is not working at all. I still get the errors.

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

I am currently using XMLMate for my validations and I have double checked it agains several online verifiers as well. The error still persists. Any suggestions would be great.

<?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> 表示该值在那里并且它的值是一个空字符串.

A node like < HarvPop>< /HarvPop> is stating that the value is there and that it's value is an empty string.

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

Based on the information on this w3.org page: http://www.w3.org/TR/xmlschema-0/#Nils

nillable 属性是这样使用的:

The nillable attribute is used like this:

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

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

即您必须特别声明该值为空.

ie You have to specifically state that the value is null.

另一种方法是声明 minoccurs = 0,以允许该值丢失.

The other way to do it is to state minoccurs = 0, to allow the value to be missing.

这篇关于XSD 属性 NILLABLE 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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