3

let's say I have below standard.xsd file piece of code,

<xs:complexType name="StdBasicTags">
        <xs:sequence>
            <xs:element name="Name" type="xs:string" nillable="true">
                <xs:annotation>
                    <xs:documentation>Name</xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

Now I have another XSD file which inlcudes above file and adds some additional element to above complexType StdBasicTags

The file name is fullStandard.xsd and the way I have extended the StdBasicTags is as follows :

<xs:include schemaLocation="standard.xsd"/>
........
........
    <xs:complexType name="FullStdBasicTags">
            <xs:complexContent>
                <xs:extension base="StdBasicTags">
                    <xs:sequence>
                        <xs:element name="Surname" type="xs:string">
                            <xs:annotation>
                                <xs:documentation>Last name</xs:documentation>
                            </xs:annotation>
                        </xs:element>
                    </xs:sequence>
                </xs:extension>
            </xs:complexContent>
        </xs:complexType>

I have following queries,

  1. I am using licensed Altova XmlSpy tool to generate Sample xml for fullStandard.xsd file but I can only see the Name element and not the Surname element as expected. Can anyone tell what is the possible reason to it, what is it that I am missing?

  2. I am having to give another name which is FullStdBasicTags for extending the StdBasicTags and adding a new element. In this case what is going to be the output of the full final XML file? The idea is to have both Name and Surname under same parent complexType StdBasicTags.

  3. Lastly, is there anything wrong with the architecture/output I am expecting?

Note** both the files are getting validated correctly. Also the idea is to achieve what I have just mentioned without making any changes to the standard.xsd file.

**UPDATE I am surprised that till now no one got any suggestions to me. Meanwhile I tried this,

   <xs:element name="FullNewRoot">
    <xs:complexType>
      <xs:sequence>
          <xs:element ref="rootElementName"/>
      </xs:sequence>
    </xs:complexType>
   </xs:element>

Where rootElementName is the root element of standard.xsd. After adding this now I am able to see the additional elements. But now the trouble is that, entire standard.xsd structure is appearing first and then whatever I have redefined in fullStandard.xsd is appearing, while I just want all of them for once.

Please please suggest something.

coretechie
  • 1,050
  • 16
  • 38
  • Please show **complete** XML Schema documents that we can use to reproduce your issue. For instance, the definition of the `String` type is not shown. A sample XML document that you want to be valid against fullstandard.xsd would be helpful. More help over here: http://stackoverflow.com/help/mcve. – Mathias Müller Jan 04 '16 at 14:21
  • Hi @Mathias Müller, `String` is nothing but same as `xs:string`. I have edited the question. I hope this is a Minimal, Complete, and Verifiable example now. – coretechie Jan 05 '16 at 07:10

1 Answers1

1

Please find answers for your questions below.

  1. The possible reason is the type of the element. The type should be FullStdBasicTags if you're using StdBasicTags.

  2. The parent type cannot refer to the new property added in the child type. The same principles of inheritance applies here.

Please find the samples below.

StdSchema.xsd

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/StdSchema"
    xmlns:tns="http://www.example.org/StdSchema" elementFormDefault="qualified">
    <complexType name="StdBasicTags">
        <sequence>
            <element name="Name" type="string" nillable="true">
                <annotation>
                    <documentation>Name</documentation>
                </annotation>
            </element>
        </sequence>
    </complexType>
</schema>

FullSchema.xsd

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/FullSchema"
    xmlns:tns="http://www.example.org/FullSchema" elementFormDefault="qualified"
    xmlns:tst="http://www.example.org/StdSchema">
    <include schemaLocation="StdSchema.xsd" />
    <import schemaLocation="StdSchema.xsd" namespace="http://www.example.org/StdSchema"></import>
    <complexType name="FullStdBasicTags">
        <complexContent>
            <extension base="tst:StdBasicTags">
                <sequence>
                    <element name="Surname" type="string">
                        <annotation>
                            <documentation>Last name</documentation>
                        </annotation>
                    </element>
                </sequence>
            </extension>
        </complexContent>
    </complexType>

    <element name="TestTag" type="tns:FullStdBasicTags"/>
</schema>

Sample XML:

<?xml version="1.0" encoding="UTF-8"?>
<tns:TestTag xmlns:tns="http://www.example.org/FullSchema" xmlns:tns1="http://www.example.org/StdSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org/FullSchema FullSchema.xsd ">
  <tns1:Name>tns1:Name</tns1:Name>
  <tns:Surname>tns:Surname</tns:Surname>
</tns:TestTag>
Shyamkumar
  • 41
  • 1
  • 3
  • Thanks for your time. However the second `FullSchema.xsd` file is invalid with following error : `src-include.2.1: The included schema's target namespace 'http://www.example.org/StdSchema' must be absent or match the including schema's value 'http://www.example.org/FullSchema'.` I have tried the similar thing before, but this error doesn't let the file be validated. any idea what can be done here? I have tried several combinations of namespaces in both the files. – coretechie Jan 06 '16 at 07:35
  • I have removed the `` tag from FullSchema.xsd, now it is valid one. – coretechie Jan 06 '16 at 07:54
  • Why was the edit rejected? Where have you seen both and tags present at the same type in an xsd file. One needs targetNameSpace to be same and the other one needs them to be different. Please go and validate the files once before rejecting any edit!!!! – coretechie Jan 07 '16 at 07:48