Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 19th, 2006, 07:25 PM
mflll@wiu.edu
Guest
 
Posts: n/a
Default Including element from one schema namespace in another schema namespace

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
mflll@wiu.edu

  #2  
Old July 20th, 2006, 07:45 AM
George Bina
Guest
 
Posts: n/a
Default Re: Including element from one schema namespace in another schema namespace

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
---------------------------------------------------------------------
George Cristian Bina
<oXygen/XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

mflll@wiu.edu wrote:
Quote:
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
mflll@wiu.edu
 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles