XSD extends complex type

I am trying to expand an existing complextype in an XSD file.

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

The problem I am running into is that it adds my extension, but it removes existing items other than those defined in the asset_abstract file

Am I trying to do this?

Code I don't want to change

<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 that I can import to extend the schema.

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

      

OK. I created bare bones and I still can't get it to work now using visual studio as I want to make sure it's not a tool :) I still can't get it to work the same way as yours :( I must be missing something.

Basically I added 2 files Master.xsd and local.xsd The wizard wraps the remote project which I can't / don't want to modify directly, and local.xsd is all the elements of our site (overriding it as it's 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

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

      

And where I override all the time.

+2


source to share


1 answer


If you want to keep the complex type name as "Feature_Cadastre_Lot" and add it with additional content, then you look at overriding . The net effect is that all references to "Feature_Cadastre_Lot", existing and new, will include the newly added content.

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

The override has the following layout:

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

      

The result will look like this:



Redefined type

You can see the highlighted sequence as shown in the added content.

In Visual Studio 2010, the content is also displayed fine:

VS2010 redefine

Pay attention to the second sequence below.

+3


source







All Articles