xml 架构类型未声明或缺失

xml schema type is not declared or is missing

在过去的一天里,我一直在与此作斗争,并且在 SO 上阅读了无数其他 post 的文章,他们都对我的问题给出了相同的建议。但是,该建议对我不起作用。我正在使用来自 HL7 的 CDA 格式的 xsd 文件来尝试生成我的 类(不幸的是,文件太大,无法在此处 post)。以下是架构的相关部分:

<xs:schema targetNamespace="urn:hl7-org:v3" xmlns:mif="urn:hl7-org:v3/mif" xmlns="urn:hl7-org:v3" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">

    <xs:element name="POCD_MT000040.ClinicalDocument" type="ClinicalDocument"/> <!-- error message points to the "<xs:element" on this line -->
<xs:complexType name="POCD_MT000040.ClinicalDocument">
    <xs:sequence>
        <xs:element name="realmCode" type="CS" minOccurs="0" maxOccurs="unbounded"/>
        <xs:element name="typeId" type="POCD_MT000040.InfrastructureRoot.typeId"/>
        <xs:element name="templateId" type="II" minOccurs="0" maxOccurs="unbounded"/>
        <xs:element name="id" type="II"/>
        <xs:element name="code" type="CE"/>
        <!-- many more elements follow -->
    </xs:sequence>
</xs:complexType>

我在 SO 上发现了很多 postings 来自报告类似消息的人。他们都说问题是缺少默认的命名空间,或者 complexType 需要附带的 "xs:element" 声明。如您所见,我两者都有。那么为什么会这样呢?

我应该补充一点,我曾尝试使用 XmlSpy 从 xsd 生成 类,但它报告了同样的错误。但是,我的特定工具来自 .NET。我从 Visual Studio、xsd.exe 和 xml2code 收到了同样的错误。

如有任何想法或建议,我们将不胜感激!

解决方案: 将代码减少到绝对最小值(根据请求)后,它帮助我隔离了问题。解决方案是使 xs:element 声明中 'type' 中的文本与 xs:complexType 声明中的 'name' 匹配。进行此更改允许 xsd.exe 工具从 .xsd 文件生成 类。

<xs:element name="POCD_MT000040.ClinicalDocument" type="ClinicalDocument"/>
<xs:complexType name="ClinicalDocument"> <!-- took out "POCD_MT00040." -->
    <xs:sequence>
        <xs:element name="realmCode" type="CS" minOccurs="0" maxOccurs="unbounded"/>
        <!-- many more elements follow -->
    </xs:sequence>
</xs:complexType>