【问题标题】:validation pass if there's a date or if there's an empty node如果有日期或有空节点,则验证通过
【发布时间】:2014-01-13 12:12:49
【问题描述】:

如果有日期或有空节点,我想要验证通过

<Start_Date>2011-05-31</Start_Date>应该还可以

<Start_Date></Start_Date>

我的xml如下

<Start_Date xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
            xsi:nil="true"></Start_Date>

而我的xsd如下

<xs:element name="Start_Date" nillable="true" type="xs:date" />

如果节点不为空,我的验证可以正常工作,但是每当我尝试传递日期时都会抛出异常,提示“Start_Date 不能包含字符或元素信息[子],因为指定了 http://www.w3.org/2001/XMLSchema-instance,nil

【问题讨论】:

    标签: xml xsd-validation


    【解决方案1】:

    听起来好像引发错误的 XML 不是

    <Start_Date>2011-05-31</Start_Date> 
    

    但是

    <Start_Date 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:nill='true'
    >2011-05-31</Start_Date>`
    

    【讨论】:

      猜你喜欢
      • 2013-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-23
      • 2015-06-02
      相关资源
      最近更新 更多