Broken Link
Broken Link

Reputation: 2440

Reference XML Schema extension

I have simple schema like this

> <?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="employee" type="fullpersoninfo"/>

<xs:complexType name="personinfo">
  <xs:sequence>
    <xs:element name="firstname" type="xs:string"/>
    <xs:element name="lastname" type="xs:string"/>
  </xs:sequence>
</xs:complexType>

<xs:complexType name="fullpersoninfo">
  <xs:complexContent>
    <xs:extension base="personinfo">
      <xs:sequence>
        <xs:element name="address" type="xs:string"/>
        <xs:element name="city" type="xs:string"/>
        <xs:element name="country" type="xs:string"/>
      </xs:sequence>
    </xs:extension>
  </xs:complexContent>
</xs:complexType>

In a different schema I want to refer the personinfo:country, how do I refer this?

<xs:element name="country" type="how do i refer this" minOccurs ="0" maxOccurs ="1">
</xs:element>

Upvotes: 0

Views: 187

Answers (1)

C. M. Sperberg-McQueen
C. M. Sperberg-McQueen

Reputation: 25034

The author of your simple schema has worked hard to make it impossible to refer to the 'country' element from another schema document, by making it local to the fullpersoninfo type, instead of making it a top-level element. If the schema cannot be changed, you're hosed.

If the schema can be changed to make it possible to reuse the constructs you want to reuse, then you will need to include or import the relevant schema documents, and then you will refer to them using their qualified names. But it looks as if you're a bit uncertain whether you want to refer to the country element or to the type of the country element; you'll need to make up your mind if you want to produce a coherent schema.

Upvotes: 1

Related Questions