473,405 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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

Jul 19 '06 #1
1 1558
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

mf***@wiu.edu 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"
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
mf***@wiu.edu
Jul 20 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: wooks | last post by:
<?xml version="1.0" ?> - <xsd:schema targetNamespace="urn:faster:userlogin" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:faster:userlogin"> <xsd:include...
0
by: Tony Prichard | last post by:
Hi I would like to specify an XML schema that would allow an XML document to be included within another XML document. The following example schema gives an idea of what we're trying to achieve ...
4
by: Gordon Dickens | last post by:
I have target xml to generate from schema. All of the XML instances have the same global element i.e. <base>. I would like to combine all of the schemas into a single schema where I could...
2
by: Stanimir Stamenkov | last post by:
I'm trying to find out if it is permissible to include a schema document with absent target namespace to a schema with specified target namespace, and if it is, what are the rules to resolve the...
2
by: Tarren | last post by:
Hi: The problem I am having is when I validate an xml file to a schema, it is erroring out every element. I think this has something to do with me defining/referencing the namespaces. I have...
6
by: Martin | last post by:
Hi, I have a xml file like the one below <?xml version="1.0" encoding="utf-8"?><e1 xmlns:e1="http://tempuri.org/Source1.xsd" e1:att1="1" e1:att2="2" e1:rest="345"/> If I try to create a...
3
by: namewitheldbyrequest | last post by:
"The XML element 'EnableTheming' from namespace 'http://tempuri.org/' is already present in the current scope" I created a Web Service: I imported System.Data.SqlClient so I could access SQL...
16
by: TT (Tom Tempelaere) | last post by:
Hi all, I created an XSD to define the structure of an XML file for my project. I made an XML file linked to the XSD using XmlSpy. The problem is that if I read the file using .NET XmlDocument...
0
by: icesign | last post by:
I know that the selector of these elements has a scope relative to the element being declared, but maybe there is a way to get beyond bounds of this scope or maybe just a way to extend base element?...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.