XSD扩展了复杂类型

时间:2012-04-10 06:33:23

标签: xsd

我正在尝试在XSD文件中扩展现有的complextype。

我创建了一个新的xsd文件,并将其包含在所有主XSD文件包含的末尾。

我遇到的问题是它似乎添加了我的扩展,但它删除了除asset_abstract中定义的元素之外的现有元素

我正在尝试做什么?

代码我不想修改

<xs:complexType name="Feature_Cadastre_Lot" abstract="false">
<xs:annotation>
  <xs:documentation>Represents the boundary of a titled, or proposed lot</xs:documentation>
</xs:annotation>
<xs:complexContent>
  <xs:extension base="asset_abstract">
    <xs:sequence minOccurs="1" maxOccurs="1">
      <xs:element name="LotNo" type="String_32" minOccurs="1" maxOccurs="1" nillable="false">
        <xs:annotation>
          <xs:documentation>The lot number as described on the originating survey plan</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="PlanNo" type="String_32" minOccurs="1" maxOccurs="1" nillable="false">
        <xs:annotation>
          <xs:documentation>The plan number of the originating survey plan.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="CancelledLotPlan" type="String_32" minOccurs="1" maxOccurs="1" nillable="true">
        <xs:annotation>
          <xs:documentation>The lot on plan cancelled by this boundary if applicable.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="TitledArea_sqm" type="Float_Positive_NonZero" minOccurs="1" maxOccurs="1" nillable="false">
        <xs:annotation>
          <xs:documentation>The area in square metres enclosed by the boundary, as described by the survey plan.</xs:documentation>
        </xs:annotation>
      </xs:element>
      <xs:element name="Geometry" type="geometry_area_multipatch_simple" minOccurs="1" maxOccurs="1" nillable="false">
        <xs:annotation>
          <xs:documentation>The geometry of this feature in coordinate space.  May contain holes and islands. Boundaries must consist of straight lines.</xs:documentation>
        </xs:annotation>
      </xs:element>
    </xs:sequence>
  </xs:extension>
</xs:complexContent>

我可以导入代码以扩展方案。

  <xs:complexType name="Feature_Cadastre_Lot">
<xs:complexContent>
    <xs:extension base="asset_abstract">
        <xs:sequence>
            <xs:element name="LMS_ID_1" type="String_32" minOccurs="1" maxOccurs="1" nillable="false">
                <xs:annotation>
                    <xs:documentation>The Land Management System ID as defined by the LMS Team</xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="LMS_ID_2" type="String_32" minOccurs="1" maxOccurs="1" nillable="false">
                <xs:annotation>
                    <xs:documentation>The Land Management System ID as defined by the LMS Team</xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:sequence>
    </xs:extension>
</xs:complexContent>

好的我已经创建了一个简单的骨骼,我现在仍然无法使用视觉工作室让它工作,因为我想确保它不是工具:),我仍然无法得到它,因为你的工作是:(我一定是错过了什么。

基本上我添加了两个文件Master.xsd和local.xsd Master包装远程项目我不能/不想直接修改和local.xsd是所有我们网站特定的东西(重新定义,因为它被称为)。

Master.xsd

    <?xml version="1.0"?>
<xs:schema version="1.0.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
  <xs:include schemaLocation="project.xsd">
  </xs:include>
    <xs:include schemaLocation="local.xsd">
    <xs:annotation>
      <xs:documentation>A File I can add my overwrites to</xs:documentation>
    </xs:annotation>
  </xs:include>
  </xs:schema>

project.xsd

    <?xml version="1.0"?>
<xs:schema version="1.0.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
  <xs:include schemaLocation="remote.xsd">
    <xs:annotation>
      <xs:documentation>A File that contains the complexType I want to add elments to. But not modify otherwise</xs:documentation>
    </xs:annotation>
  </xs:include>
  <xs:element name="Master_Project">
    <xs:annotation>
      <xs:documentation>The Project.</xs:documentation>
    </xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="ProjectData">
            <xs:complexType>
                <xs:sequence>
                <xs:element name="ExistingElement" type="ExistingElementType">
                  <xs:annotation>
                    <xs:documentation>An Existing Element That I would Like To Add To.</xs:documentation>
                  </xs:annotation>
                </xs:element>
              </xs:sequence>
            </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

local.xsd

    <?xml version="1.0"?>
<xs:schema version="1.0.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
  <xs:redefine schemaLocation="./remote.xsd">
   <xs:complexType name="ExistingElementType">
      <xs:complexContent>
        <xs:extension base="ExistingElementType">
           <xs:sequence>
             <xs:element name="newTest"/>
            </xs:sequence>
         </xs:extension>
      </xs:complexContent>
   </xs:complexType>
</xs:redefine>
</xs:schema>

remote.xsd

<?xml version="1.0"?>
<xs:schema version="1.0.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:complexType name="ExistingElementType">
   <xs:sequence>
      <xs:element name="someProperty"/>
      <xs:element name="someSecondProperty"/>
   </xs:sequence>
</xs:complexType>
</xs:schema>

我最终完成所有重新定义。

1 个答案:

答案 0 :(得分:4)

如果您想将复杂类型的名称保留为“Feature_Cadastre_Lot”使用其他内容对其进行扩展,那么您正在查看重新定义。实际效果是所有对“Feature_Cadastre_Lot”的引用,包括新添加的内容。

如果你想在一些但不是所有现有内容中使用它,则没有解决方案(重新定义全部或全部)。

重新定义具有以下布局:

<xs:redefine schemaLocation="must resolve to your XSD">
  <xs:complexType name="Feature_Cadastre_Lot">
    <xs:complexContent>
      <xs:extension base="Feature_Cadastre_Lot">
        <xs:sequence>
            <xs:element name="LMS_ID_1" type="String_32" minOccurs="1" maxOccurs="1" nillable="false">
                <xs:annotation>
                    <xs:documentation>The Land Management System ID as defined by the LMS Team</xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="LMS_ID_2" type="String_32" minOccurs="1" maxOccurs="1" nillable="false">
                <xs:annotation>
                    <xs:documentation>The Land Management System ID as defined by the LMS Team</xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
</xs:redefine>

结果如下:

Redefined type

您可以看到突出显示的序列显示添加的内容。

在Visual Studio 2010中,内容也显示ok:

VS2010 redefine

注意底部的第二个序列。