Go Back   Velocity Reviews > Newsgroups > XML
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

XML - Including element from one schema namespace in another schema namespace

 
Thread Tools Search this Thread
Old 07-19-2006, 07:27 PM   #1
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"
xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
xmlnssd="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"
xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
xmlnssd="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
  Reply With Quote
Old 07-20-2006, 07:48 AM   #2
George Bina
 
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

wrote:
> 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"
> xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
> xmlnssd="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"
> xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
> xmlnssd="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
>


  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump