Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 验证属性中的空字符串_Xml_Xsd - Fatal编程技术网

Xml 验证属性中的空字符串

Xml 验证属性中的空字符串,xml,xsd,Xml,Xsd,我正在编写一个XSD模式来验证一个文档,其中存储了大量result元素。此元素的两个属性,clickIndex和timeview是可选的,并使用内置的数据类型nonNegativeInteger和decimal。与其在未设置属性值时删除这些属性,不如将其设置为空字符串,如下所示: <Page resultCount="10" visited="true"> <Result index="1" clickIndex="1" timeViewed="45.21" pid="

我正在编写一个XSD模式来验证一个文档,其中存储了大量
result
元素。此元素的两个属性,
clickIndex
timeview
是可选的,并使用内置的数据类型
nonNegativeInteger
decimal
。与其在未设置属性值时删除这些属性,不如将其设置为空字符串,如下所示:

<Page resultCount="10" visited="true">
    <Result index="1" clickIndex="1" timeViewed="45.21" pid="56118" title="alpha"/>
    <Result index="2" clickIndex="" timeViewed="" pid="75841" title="beta"/>
    <Result index="3" clickIndex="2" timeViewed="21.45" pid="4563" title="gamma"/>
    <Result index="4" clickIndex="" timeViewed="" pid="44546" title="delta"/>
    <Result index="5" clickIndex="" timeViewed="" pid="1651" title="epsilo"/>
    <Result index="6" clickIndex="" timeViewed="" pid="551651" title="zeta"/>
    <Result index="7" clickIndex="" timeViewed="" pid="20358" title="eta"/>
    <Result index="8" clickIndex="" timeViewed="" pid="61621" title="theta"/>
    <Result index="9" clickIndex="" timeViewed="" pid="135154" title="iota"/>
    <Result index="10" clickIndex="" timeViewed="" pid="95821" title="kappa"/>
</Page>

不幸的是,这无法针对以下xsd进行验证:

<xs:element name="Result">
    <xs:complexType>
        <xs:attribute name="index" type="xs:nonNegativeInteger" use="required"/>
        <xs:attribute name="clickIndex" type="xs:nonNegativeInteger" use="optional"/>
        <xs:attribute name="timeViewed" type="xs:decimal" use="optional"/>
        <xs:attribute name="pid" type="xs:positiveInteger" use="required"/>
        <xs:attribute name="title" type="xs:string" use="required"/>
    </xs:complexType>
</xs:element>

是否无法验证已定义类型的属性上的空字符串?有没有一种方法可以在不定义自定义类型的情况下执行此操作?我只是忘记了XSD中的一个选项吗


我将处理这些XML文件以生成统计信息,其中缺少的属性可能会带来不必要的复杂性。如果没有解决方法,我就用零替换空值。我更喜欢保留空字符串,因为它看起来更干净,但可能零也会更有效。

如果所讨论的属性是整数类型,则不能分配空字符串。引号中的值应该能够解析为整数。您必须像前面所说的那样用零值更新xml,或者删除包含空字符串值的属性。如果您不喜欢这两种解决方案中的任何一种,那么您必须定义自己的自定义类型。有关更多详细信息,请参阅本手册


简明扼要,我应该意识到解析问题。