xml - src 解析 : Cannot resolve the name 'ds:Signature' to an 'element declaration' component

标签 xml xsd xml-validation

我想使用 XSD 文件进行模式验证。当我将 XSD 文件导入 Eclipse 时,没有运行验证类,出现以下错误:

src-resolve: Cannot resolve the name 'ds:Signature' to an 'element declaration' component

我对 XML 与 XSD 验证过程有点陌生。虽然我在谷歌上寻找过类似的问题,但我无法弄清楚这里出了什么问题。

XSD文件如下:

 <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xerces="http://xerces.apache.org"
        xmlns:xades="http://uri.etsi.org/01903/v1.3.2#" xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
        xmlns:abc="http://abc.123.com" targetNamespace="http://abc.123.com"
        xmlns:xades141="http://uri.etsi.org/01903/v1.4.1#" elementFormDefault="qualified"
        attributeFormDefault="unqualified">
        <xs:import namespace="http://uri.etsi.org/01903/v1.3.2#" schemaLocation="XAdES.xsd"/>
        <xs:import namespace="http://uri.etsi.org/01903/v1.4.1#" schemaLocation="XAdESv141.xsd"/>
        <xs:import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="xmldsig-core-schema.xsd"/>
    <xs:complexType name="headerType">
        <xs:sequence>
            <xs:element name="doorNumber" type="xs:int"/>
            <xs:element ref="ds:Signature"/>
        </xs:sequence>
    </xs:complexType>

我应该如何修改 XSD 以修复此错误?

最佳答案

如果您有xmldsig-core-schema.xsd在与您的 XSD 相同的目录中,如果它与 this XSD 相同, 那么你不应该得到关于未能解决 ds:Signature 的错误.

因此,我怀疑您的导入失败,并且您遗漏或忽略了如下警告:

[Warning] try.xsd:9:56: schema_reference.4: Failed to read schema document 'xmldsig-core-schema.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.

试试这个 XSD 作为测试;它直接从 xmldsig-core-schema.xsd 的 URL 加载:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
           xmlns:abc="http://abc.123.com"
           targetNamespace="http://abc.123.com"
           elementFormDefault="qualified"
           attributeFormDefault="unqualified">
  <xs:import namespace="http://www.w3.org/2000/09/xmldsig#"
             schemaLocation="http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd"/>
  <xs:complexType name="headerType">
    <xs:sequence>
      <xs:element name="doorNumber" type="xs:int"/>
      <xs:element ref="ds:Signature"/>
    </xs:sequence>
  </xs:complexType>
</xs:schema>

我测试了上面的 XSD,发现它消除了您看到的分辨率错误。

关于xml - src 解析 : Cannot resolve the name 'ds:Signature' to an 'element declaration' component,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30924686/

相关文章:

xml - 架构问题 : The global element ' ' has already been declared

xml - 在 XML DTD 中使用 + 运算符

xml - 如何为 xmllint 设置目录文件?

android - RadioButton 的异常行为

c# - C#中如何直接选择节点

XML 解析错误 : not well-formed ? 任何人都可以

xml - cvc-complex-type.2.4.a : invalid content was found starting with element 'ProcessDesc' . ProcessName 预期之一

xml - XSD <xs :key> separate uniqueness constraints for different elements?

java - log4j2.xml 创建文件,但不输出文件中的任何内容

android - 客户端(浏览器)的 XSLT 转换支持