Including element from one schema namespace in another schema namespace

mflll

Usenet Archive
Joined
Jan 17, 2006
Messages
9
Reaction score
0
How does one say in one schema that one wants an element defined in another schema. For example, I want to include in the Employee definition, an Address element defined in the schema http://test.org.Address

Here is the schema defining the Employee:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://test.org/emp" xmlns="http://test.org/emp" xmlns:addr="http://test.org/Address" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" version="2.0"> <xsd:import namespace="http://test.org/Address" schemaLocation="Address.xsd"/>

<xsd:complexType name = "EmployeeType">
<xsd:sequence>
<xsd:element ref="Name" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="JobInfo" minOccurs="0" maxOccurs="unbounded"/> <xsd:element ref="Salary" minOccurs="0" maxOccurs="1" /> <addr:Address minOccurs="1" maxOccurs="1"/> </xsd:sequence> </xsd:complexType> ....
</xsd:schema>

Here is the definition of the Address:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://test.org/Address" xmlns="http://test.org/address" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" version="2.0">

<xsd:complexType name="addressType">
<xsd:sequence>
<xsd:element minOccurs="1" maxOccurs="unbounded"
name="Line"><xsd:simpleType><xsd:restriction
base="xsd:string"/></xsd:simpleType></xsd:element>
<xsd:element minOccurs="1" maxOccurs="1"
name="City"><xsd:simpleType><xsd:restriction
base="xsd:string"/></xsd:simpleType></xsd:element>
<xsd:element minOccurs="1" maxOccurs="1"
name="State"><xsd:simpleType><xsd:restriction
base="xsd:string"/></xsd:simpleType></xsd:element>
<xsd:element minOccurs="1" maxOccurs="1"
name="zip"><xsd:simpleType><xsd:restriction
base="xsd:string"/></xsd:simpleType></xsd:element>
</xsd:sequence>
</xsd:complexType >
<xsd:element name="address" type="addressType"/>
</xsd:schema>

This gives me an error message.

Note, I have no problems bringing in a type from one schema into another. That is, I created an addressType in the http://test.org/Address name space. I used that just fine to define an element in the http://test.org/emp Schema. I am wondering if there is a way to bring in an element itself from one schema into another.

(I also tried writing using the ref attribute, but ref requires a QName, not a NCName. So I got a syntax error message if I was to write <xsd:element ref="emp:Address")

Dr. Laurence L. Leff, Ph.D. Associate Professor of Computer Science Western Illinois University 1 University Circle Macomb IL 61455 309 367 0787
 

George Bina

Usenet Archive
Joined
Jan 30, 2004
Messages
134
Reaction score
0
Hi,

First note that XML Schema component names are case sensitive and address and Address are different components. If you want to specify that the content of EmployeeType should contain an element from the http://test.org/Address namespace named address then use

<xs:element ref="addr:address"/>

Best Regards,
George
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,049
Messages
3,104,246
Members
248,133
Latest member
DujonT

Latest Threads

Top