src-resolve: 无法将名称 'ds:Signature' 解析为 'element declaration' 组件
src-resolve: Cannot resolve the name 'ds:Signature' to an 'element declaration' component
我想使用 XSD 文件进行模式验证。当我将 XSD 文件导入 Eclipse 时,没有 运行 验证 class,出现以下错误:
src-resolve: Cannot resolve the name 'ds:Signature' to an 'element
declaration' component
我对 XML 和 XSD 验证过程有点陌生。虽然我在 google 上寻找过类似的问题,但我无法弄清楚这里出了什么问题。
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 作为测试;它直接从 URL 加载 xmldsig-core-schema.xsd
:
<?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,发现它消除了您看到的分辨率错误。
作为替代方案,您可以在本地缓存 xmldsig-core-schema.xsd
,将其放在 xsd 架构的同一目录中,然后让您的原始
<xs:import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="xmldsig-core-schema.xsd"/>
这将解决您从 W3C 网站导入文件的问题并节省执行时间。
我刚刚使用 Visual Studio 2019 和 运行 从 cXML DTD 文件生成了 XSD 文件,但遇到了同样的问题。
在我的案例中,解决方案包含多个步骤:
- 将数字签名架构文件
xmldsig-core-schema.xsd
(可从 https://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd 下载)保存在与 cXML 架构文件相同的文件夹中
- 搜索并替换所有出现的
xmlns:ds="uri:ds"
为 xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
- 查找并删除
<xs:import namespace="uri:ds" />
的所有出现运行
经过这些步骤后,cXML 模式文件得到验证,我能够使用命令生成 C# 类:
xsd /c cXML.xsd xmldsig-core-schema.xsd
注意: xsd
工具需要传入两个模式。
我通过修改以下行更新了 .xsd 文件:
<xsd:import namespace="http://www.w3.org/2000/09/xmldsig#"
schemaLocation="http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd"/>
我想使用 XSD 文件进行模式验证。当我将 XSD 文件导入 Eclipse 时,没有 运行 验证 class,出现以下错误:
src-resolve: Cannot resolve the name 'ds:Signature' to an 'element declaration' component
我对 XML 和 XSD 验证过程有点陌生。虽然我在 google 上寻找过类似的问题,但我无法弄清楚这里出了什么问题。
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 作为测试;它直接从 URL 加载 xmldsig-core-schema.xsd
:
<?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,发现它消除了您看到的分辨率错误。
作为替代方案,您可以在本地缓存 xmldsig-core-schema.xsd
,将其放在 xsd 架构的同一目录中,然后让您的原始
<xs:import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="xmldsig-core-schema.xsd"/>
这将解决您从 W3C 网站导入文件的问题并节省执行时间。
我刚刚使用 Visual Studio 2019 和 运行 从 cXML DTD 文件生成了 XSD 文件,但遇到了同样的问题。
在我的案例中,解决方案包含多个步骤:
- 将数字签名架构文件
xmldsig-core-schema.xsd
(可从 https://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd 下载)保存在与 cXML 架构文件相同的文件夹中 - 搜索并替换所有出现的
xmlns:ds="uri:ds"
为xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
- 查找并删除
<xs:import namespace="uri:ds" />
的所有出现运行
经过这些步骤后,cXML 模式文件得到验证,我能够使用命令生成 C# 类:
xsd /c cXML.xsd xmldsig-core-schema.xsd
注意: xsd
工具需要传入两个模式。
我通过修改以下行更新了 .xsd 文件:
<xsd:import namespace="http://www.w3.org/2000/09/xmldsig#"
schemaLocation="http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd"/>