You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

XML校验XSD时出现‘Cannot Find The Declaration Of Element 'Document'’错误求解决

解决XML验证错误:Cannot Find The Declaration Of Element 'Document'

问题根源

你的XSD指定了目标命名空间rn:iso:std:iso:20022:tech:xsd:uth.30.01.3,且设置elementFormDefault="qualified",这意味着XSD中定义的所有元素(包括<Document>)都属于该命名空间。但你的XML中的<Document>元素没有关联到这个命名空间,导致验证器无法匹配到对应的元素声明。

修复方案

方案1:修改XML,引入命名空间

在XML的根元素<Document>上添加命名空间声明,将其归属到XSD的目标命名空间:

<?xml version='1.0' encoding='utf-8'?>
<Document xmlns="rn:iso:std:iso:20022:tech:xsd:uth.30.01.3">
    <DerivsTradRpt>
        <RptgTmStmp>2024-03-13T13:24:23Z</RptgTmStmp>
        <TradData>
            <Rpt>
...
        </TradData>
    </DerivsTradRpt>
</Document>

这样XML中的所有元素会通过默认命名空间生效,归属到指定的命名空间,和XSD中的元素声明匹配。

方案2:修改XSD,移除命名空间(不推荐,除非特殊需求)

如果不需要命名空间,可以删除XSD中的targetNamespace和默认命名空间声明:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xs:element name="Document" type="Document"/>
    <xs:simpleType name="ActiveCurrencyCode">
        <xs:annotation>
            <xs:documentation source="Name" xml:lang="EN">ActiveCurrencyCode</xs:documentation>
            <xs:documentation source="Definition" xml:lang="EN">A code allocated to a currency by a Maintenance Agency under an international identification scheme as described in the latest edition of the international standard ISO 4217 "Codes for the representation of currencies and funds".</xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:string">
            <xs:pattern value="[A-Z]{3,3}"/>
        </xs:restriction>
    </xs:simpleType>
</xs:schema>

注意:这种方式不符合ISO 20022标准的常规用法,仅在非标准场景下使用。

额外提示

你的XSD中定义了<xs:element name="Document" type="Document"/>,但未提供Document复杂类型的完整定义,后续验证时还会出现该类型未找到的错误,需要补充Document类型的结构定义(比如包含<DerivsTradRpt>等子元素的规则)。

内容的提问来源于stack exchange,提问作者Bernd

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 05:43:13