xmlxsdhl7-cda

xml schema type is not declared or is missing


I have been fighting this for the past day and read countless other posts here on SO that all give the same advice for my problem. However, that advice is not working for me. I am using the xsd files for the CDA format from HL7 to try and generate my classes (unfortunately the files are too large to post here). Here are the relevant parts of the schema:

<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>

I have found dozens of postings here on SO from people reporting similar messages. All of them say the problem is either that a default Namespace is missing or the complexType needs an accompanying "xs:element" declaration. As you can see I have both. So why is this happening?

I should add I have tried using XmlSpy to generate the classes from the xsd with it reporting the same error. However, my specific tools are from .NET. I have received the same error from Visual Studio, xsd.exe, and xml2code.

Any thoughts or ideas would be greatly appreciated!


Solution

  • SOLUTION: After cutting the code down to the absolute minimum (per request) it helped me to isolate the problem. The solution was to make the text in the 'type' on the xs:element declaration match the 'name' on the xs:complexType declaration. Making this change allowed the xsd.exe tool to generate the classes from the .xsd file.

    <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>