Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.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 如何修复XSD验证错误?_Xml_Xsd - Fatal编程技术网

Xml 如何修复XSD验证错误?

Xml 如何修复XSD验证错误?,xml,xsd,Xml,Xsd,我有一个包含元素0的XML表单,它格式正确但无效。 当我尝试验证它时,会出现以下错误: 空元素“hidden”中不允许任何内容。 以下是我的模式: <xs:element name="hidden"> <xs:complexType> <xs:attribute name="datatype" type="xs:string" use="optional"/> <xs:attribute name="alias"

我有一个包含元素0的XML表单,它格式正确但无效。 当我尝试验证它时,会出现以下错误: 空元素“hidden”中不允许任何内容。 以下是我的模式:

<xs:element name="hidden">
    <xs:complexType>
        <xs:attribute name="datatype" type="xs:string" use="optional"/>
        <xs:attribute name="alias" type="xs:string" use="optional"/>
        <xs:attribute name="source" type="xs:string" use="optional"/>
        <xs:attribute name="name" type="xs:string" use="required"/>
        <xs:attribute name="lookup" type="xs:string" use="optional"/>
    </xs:complexType>
</xs:element>

我需要向上述模式添加什么来修复此错误?Thanx ml

您的“隐藏”元素被定义为空,因为您在模式中没有明确允许子元素的任何内容。我猜你想要的是

<hidden *[attributes]*>
   <some_other_element/>
</hidden>


但是根据你的解释,你已经隐式地定义了“隐藏”为空。您需要定义哪些元素可以显示在“隐藏”中。有很多方法可以做到这一点,我建议从阅读开始。

正如welbog所指出的,您定义了一个复杂的空元素。假设您只需要隐藏标记中的文本,您可以沿着以下几行编写模式:

<xs:element name="hidden">
  <xs:complexType>
    <xs:simpleContent>
      <xs:extension base="xs:integer">
        <xs:attribute name="datatype" type="xs:string" use="optional"/>
        <xs:attribute name="alias"    type="xs:string" use="optional"/>
        <xs:attribute name="source"   type="xs:string" use="optional"/>
        <xs:attribute name="name"     type="xs:string" use="required"/>
        <xs:attribute name="lookup"   type="xs:string" use="optional"/>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
</xs:element>

这样,您就可以得到一段XML,如下所示:

<hidden datatype="foo" name="bar">0</hidden>
0

这里发生的事情是,我将“hidden”定义为
xs:integer
的扩展(顺便说一下,您可以让它扩展任何您想要的类型),这意味着“hidden”元素类似于integers元素,但有额外的约束,或者在本例中使用附加属性。

您还没有设法以可见的方式附加您的模式-您能将它和示例XML放在某个服务器上并链接到它们吗?我修复了它-它只需要缩进四个空格即可显示。Thanx a milion weblog。谢谢你的帮助。谢谢你的解释!谢谢迈克尔和博客!向格雷格问好