在一台服务器上的空值验证失败时,我遇到了一些问题,但它在我的所有其他服务器上都能工作。此问题发生在较新的PHP版本(5.3.8)上,并在稍早的版本(5.2.4)上工作。
下面是几个失败的孤立元素:
XML输入:
<clbburnfuelbias></clbburnfuelbias>
<clbburntimebias></clbburntimebias>XSD验证:
<xs:element name="clbburnfuelbias" type="data-fuelbias"/>
<xs:element name="clbburntimebias" type="data-timebias"/>
<xs:simpleType name="data-fuelbias">
<xs:restriction base="xs:integer">
<xs:minInclusive value="-9900"/>
<xs:maxInclusive value="9900"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="data-timebias">
<xs:restriction base="xs:integer">
<xs:minInclusive value="-59"/>
<xs:maxInclusive value="59"/>
</xs:restriction>
</xs:simpleType>错误:
错误1824:元素“clbblafuel偏向”:该值不是原子类型“数据-燃料偏差”的有效值。错误1824:元素“clbburtime偏向”:该值不是原子类型的有效值 “数据-时间偏差”。
在运行5.2.4的不同服务器上使用完全相同的输入和XSD文件,我没有错误,xml是有效的。
我尝试将minOccurs="0“添加到元素中,也尝试指定nullable="true”,但仍然会出现错误。
更新:
在我的服务器上,使用PHP 5.2.4忽略null值,使用5.3.8拒绝null值。我所使用的一项工作是使用两个定义的联合,一个用于整数类型,另一个用于空值:
XSD:
<xs:element name="clbburnfuelbias" minOccurs="0">
<xs:simpleType>
<xs:union memberTypes="data-fuelbias null-string"/>
</xs:simpleType>
</xs:element>
<xs:simpleType name="data-fuelbias">
<xs:restriction base="xs:integer">
<xs:minInclusive value="-9900"/>
<xs:maxInclusive value="9900"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="null-string">
<xs:restriction base="xs:string">
<xs:length value="0"/>
</xs:restriction>
</xs:simpleType>发布于 2012-11-05 18:05:24
使元素可选(minOccurs="0")并不使其内容成为通配符。如果出现该元素,则必须与声明的类型匹配。
使元素nillable (nillable="true")允许元素为空,如果它有xsi:nil="true"属性,其中xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<clbburnfuelbias xsi:nil="true"></clbburnfuelbias>
<clbburntimebias xsi:nil="true"></clbburntimebias>您还可以使用union类型,它仅具有相同的意义,用于验证目的:
<xs:simpleType name="data-fuelbias">
<xs:union>
<xs:restriction base="xs:integer">
<xs:minInclusive value="-9900"/>
<xs:maxInclusive value="9900"/>
</xs:restriction>
<xs:restriction base="xs:string">
<xs:length value="0"/>
</xs:restriction>
</xs:union>
</xs:simpleType>发布于 2012-11-05 19:43:57
看起来,旧版本的PHP有一个bug,这个bug已经被修复了。这些元素实例显然无效。
为可以包含整数或不包含整数的元素定义简单类型的首选方法是使用itemType=integer、minLength=0、maxLength=1定义列表类型。我喜欢使用联合类型的主要原因是,它在模式感知的XSLT和XQuery中工作得更好;对于某些数据绑定产品,它也可能更好地工作。
发布于 2012-11-05 18:00:22
数据需要是在XSD中指定的值之间的整数。您正在传递一个空值。至少..。这应该是有效的。我认为您要传递的XML不应该根据模式进行验证。
也许XML解析器版本在PHP版本之间是不同的,而旧版本是宽容的。无论哪种方式,我阅读该模式都是这样的:这两个字段必须只出现一次,并且必须包含x和y之间的整数(其中x和y是在minInclusive和maxInclusive中指定的)。空值应该无法验证。
https://stackoverflow.com/questions/13237493
复制相似问题