3

我正在尝试在 XSD 文件中扩展现有的复杂类型。

我创建了一个新的 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>

好的,我已经创建了一个简单的示例,但我现在仍然无法使用 Visual Studio 让它工作,因为我想确保它不是工具 :),我仍然无法像你的那样工作 :( 我一定是遗漏了什么。

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

大师.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>

项目.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>

本地.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>

远程.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>

我最终在哪里进行所有重新定义。

4

1 回答 1

5

如果您想将复杂类型的名称保留为“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>

结果将如下所示:

重新定义类型

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

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

VS2010重新定义

注意底部的第二个序列。

于 2012-04-10T13:18:14.457 回答