xsd:complexType 在 xsd:attribute 声明之后产生错误

xsd:complexType after xsd:attribute declarations yields error

我有以下 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>   

我尝试在我的 Visual Studio 2010 Professional 中使用它。 VS告诉我<xsd:attribute name="Rel" type="xsd:string"/>后面的<xsd:complexType>是非法的。因此我不能在我想要的 VS 中使用 XSD 文件。 XSD/the table 的层级是固定的,我不能输入那个。有没有办法在属性之后将元素 "Detail" 作为 "C" 的子元素? 由于向我提供了这个文件定义,我没有自己开发 XSD 并且需要在必要时对其进行调整。

属性声明必须在之后 complexType,否则你会得到如下错误:

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

解决方案:将属性声明移到 xsd:complexType 元素下方(并删除多余的 xsd:complexType)。

还有一个问题需要解决:

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

解决方案:更改元素声明以使用现有或内置类型,或添加引用类型。

已更正 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>