XSD 验证错误:元素“{http://www.example.com}Scope”:该元素不是预期的元素。预期是(范围)

2023-11-23

我创建了以下 XSD(使用 Eclipse):

  <?xml version="1.0" encoding="UTF-8"?>
  <schema targetNamespace="http://www.example.com" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.example.com">
    <element name="Make">
      <complexType>
        <sequence>
          <element name="Scope"></element>
        </sequence>
      </complexType>
    </element>
  </schema>

并使用这个简单的 XML 进行验证

  <?xml version="1.0"?>
  <Make xmlns="http://www.example.com">
    <Scope>
    </Scope>
  </Make>

gives:

  xmllint.exe --noout --schema sources.xsd sources.xml
  sources.xml:3: element Scope: Schemas validity error : Element '{http://www.example.com}Scope': This element is not expected. Expected is ( Scope ).
  sources.xml fails to validate

在我看来,这must正确:XML 文件位于命名空间中http://www.example.com(验证者也这么说)。

对于 XSD,我将默认命名空间设置为 XSD 模式(这就是 Eclipse 所做的,所以它应该是正确的!),并且给出了正确的 targetNamespace。我也尝试使用

<element name="tnd:Scope" />

然而,这也行不通。

这是 xmllint 中的错误还是问题出在哪里?

问候 分区B


替代方案@dbasemans答案是指定elementFormDefault as 合格的:

 <schema targetNamespace="http://www.example.com"
     xmlns="http://www.w3.org/2001/XMLSchema"
     xmlns:tns="http://www.example.com"
     elementFormDefault="qualified">

使用xsd or xs您的架构命名空间的前缀可以被认为是常见的,因此可能需要选择按照以下建议修改您的架构dbaseman.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

XSD 验证错误:元素“{http://www.example.com}Scope”:该元素不是预期的元素。预期是(范围) 的相关文章

随机推荐