xsd:complexType after xsd:attribute declarations yields error

364 views Asked by At

I have the following XSD:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="urn:com.xxxxx.xxx" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:com.xxxxx.xxx">
<xsd:element name="Stuff_EXT" type="DT_Analyse_EXT"/>
<xsd:complexType name="Stuff_EXT">
<xsd:annotation>
<xsd:documentation xml:lang="EN">Data Type Response</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
  <xsd:element name="Res">
  <xsd:complexType>
  <xsd:sequence>
    <xsd:element name="Loc" maxOccurs="unbounded">
    <xsd:complexType>
    <xsd:attribute name="No" type="xsd:string"/>
    <xsd:attribute name="TP" type="xsd:string"/>
    </xsd:complexType>
    </xsd:element>
    <xsd:element name="Results" maxOccurs="unbounded">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element name="C" maxOccurs="unbounded">
    <xsd:complexType>
      <xsd:attribute name="Date" type="xsd:string"/>
      <xsd:attribute name="Result" type="xsd:string"/>
      <xsd:attribute name="Rel" type="xsd:string"/>
      <xsd:complexType>
    <xsd:sequence>
    <xsd:element name="Detail" maxOccurs="unbounded">
    <xsd:complexType>
    <xsd:attribute name="Co" type="xsd:string"/>
    <xsd:attribute name="Result" type="xsd:string"/>
    </xsd:complexType>
    </xsd:element>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:complexType>
    </xsd:element>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
  </xsd:sequence>
  </xsd:complexType>
  </xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>   

I try to use this within my Visual Studio 2010 Professional. The VS tells me that the <xsd:complexType> after the <xsd:attribute name="Rel" type="xsd:string"/> is illegal. Therefore I can not use the XSD file in VS I want to. The hierachy of the XSD/the table is fixed, I can not enter that. Is there a way to keep the element "Detail" as a sub-element of "C" after the attributs? Since I was provided with this file definition, I did not develope the XSD myself and need to adapt it, if necessary.

1

There are 1 answers

1
kjhughes On BEST ANSWER

Attribute declarations have to come after complexType, otherwise you'll get an error such as the following:

[Error] try.xsd:26:40: s4s-elt-invalid-content.1: The content of '#AnonType_CResultsResStuff_EXT' is invalid. Element 'complexType' is invalid, misplaced, or occurs too often.

Resolution: Move the attribute declarations below the xsd:complexType element (and remove the extra xsd:complexType).

There's another problem to fix too:

[Error] try.xsd:3:56: src-resolve: Cannot resolve the name 'DT_Analyse_EXT' to a(n) 'type definition' component.

Resolution: Change the element declaration to use an existing or built-in type, or add the referenced type.

Corrected XSD:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="urn:com.xxxxx.xxx"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
            xmlns="urn:com.xxxxx.xxx">
  <xsd:element name="Stuff_EXT" type="DT_Analyse_EXT"/>
  <xsd:complexType name="DT_Analyse_EXT">
    <!-- define as appropriate -->
  </xsd:complexType>
  <xsd:complexType name="Stuff_EXT">
    <xsd:annotation>
      <xsd:documentation xml:lang="EN">Data Type Response</xsd:documentation>
    </xsd:annotation>
    <xsd:sequence>
      <xsd:element name="Res">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element name="Loc" maxOccurs="unbounded">
              <xsd:complexType>
                <xsd:attribute name="No" type="xsd:string"/>
                <xsd:attribute name="TP" type="xsd:string"/>
              </xsd:complexType>
            </xsd:element>
            <xsd:element name="Results" maxOccurs="unbounded">
              <xsd:complexType>
                <xsd:sequence>
                  <xsd:element name="C" maxOccurs="unbounded">
                    <xsd:complexType>
                      <xsd:sequence>
                        <xsd:element name="Detail" maxOccurs="unbounded">
                          <xsd:complexType>
                            <xsd:attribute name="Co" type="xsd:string"/>
                            <xsd:attribute name="Result" type="xsd:string"/>
                          </xsd:complexType>
                        </xsd:element>
                      </xsd:sequence>
                      <xsd:attribute name="Date" type="xsd:string"/>
                      <xsd:attribute name="Result" type="xsd:string"/>
                      <xsd:attribute name="Rel" type="xsd:string"/>

                    </xsd:complexType>
                  </xsd:element>
                </xsd:sequence>
              </xsd:complexType>
            </xsd:element>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
    </xsd:sequence>
  </xsd:complexType>
</xsd:schema>