XSD 扩展复杂类型 [英] XSD extend a complex type

查看:43
本文介绍了XSD 扩展复杂类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to extend an existing complextype in a XSD file.

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

I have created a new xsd file and included it at the end of all the master XSD files includes.

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

The problem I'm having is that it seems to add my extension but it removes the existing elements other than those defined in asset_abstract

我正在尝试做的事情可行吗?

Is what I'm trying to do possible?

我不想修改的代码

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

我可以导入代码来扩展方案.

Code I can import to extend the scheme.

  <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 使其工作,因为我想确保它不是工具 :),我仍然无法像您一样使用它:(我一定错过了什么.

OK I've created a bare bones exmaple and I still can't get it to work now using visual studio as I wanna make sure its not the tool :) , I still can't get it too work as yours is :( I must be missing something.

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

Basically I've added 2 files Master.xsd and local.xsd Master wraps the remote project I can't / don't want to modify direct and local.xsd is where all our site specific stuff (redefining as it is called).

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

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>

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

以及我最终重新定义的地方.

And where I do all the redefining eventually.

推荐答案

如果您想将复杂类型的名称保留为Feature_Cadastre_Lot"用其他内容扩展它,那么您正在寻找在 重新定义 代替.最终效果是所有对Feature_Cadastre_Lot"的引用,无论是先前存在的还是新的,都将包括新添加的内容.

If you want to keep the name of the complex type as "Feature_Cadastre_Lot" and extend it with additional content, then you are looking at redefine instead. The net effect is that all references to "Feature_Cadastre_Lot", preexisting and new, will include the newly added content.

如果您希望在现有内容中使用它,但不是所有内容,都没有解决方案(重新定义是全有还是全无).

If you want this in some, but not all of the existing content, there is no solution to it (redefine is all or nothing).

重新定义的布局如下:

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

结果如下:

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

You can see the highlighted sequence as showing the added content.

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

In Visual Studio 2010, the content also shows ok:

注意底部的第二个序列.

Notice the second sequence at the bottom.

这篇关于XSD 扩展复杂类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆