473,386 Members | 1,745 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,386 software developers and data experts.

XML schema - Make xsd include another xsd

Hi.

I have a problem witch I assume there is an answear to....?

I have several XML schemas, and they all have quiet a lot of
definitions in common. They still have to be seperated into different
XML schemas, but what I want to do is to create one XML schema
containing all the common definitions (this is mostly type
definitions). I then want all the XML schemas I have to include this
file containing the definitions.

How do I do this?... It sounds simple, but I haven't managed to figure
out the answear yet...

Best regards,
Stian

Jul 20 '05 #1
4 2618


stiank81 wrote:

I have several XML schemas, and they all have quiet a lot of
definitions in common. They still have to be seperated into different
XML schemas, but what I want to do is to create one XML schema
containing all the common definitions (this is mostly type
definitions). I then want all the XML schemas I have to include this
file containing the definitions.

How do I do this?... It sounds simple, but I haven't managed to figure
out the answear yet...


You need at least one schema per target namespace and then use xs:import
to compose the schemas for different target namespaces.
If you want to break up a schema for one namespace and compose the parts
then use xs:include.

See the schema primer
<http://www.w3.org/TR/xmlschema-0/#SchemaInMultDocs>
<http://www.w3.org/TR/xmlschema-0/#import>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #2
Thanks - it seems to be working now :)
But I still have one problem - I'll introduce the problem with another
question :

I see everywhere that the target namespace and things like that is
defined as a web adress... Like in the w3.org examples:
<schema targetNamespace="http://www.example.com/IPO"..... and so on..

Does this have to be a web adress? My idea was just to have all the
files in the same folder on the computer... So I defined the starting
schema as follows :
<schema targetNamespace="COSTypes"
xmlns:cos="COSTypes"
xmlns="http://www.w3.org/2001/XMLSchema">
Where COSTypes is the name of the namespace I wanna create.. Is this
correct?..
Inside this schema I define some types.

I then include the schema above from a second schema - witch is the
main schema.. I there use this is the beginning :
<xs:schema targetNamespace="COSTypes"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="COSTypes">
<xs:include schemaLocation="COSTypes.xsd"/> <!-- in the same folder
-->

...followed by the definitions contained in this schema..

Both the schemas validates and workes fine.. But there is one thing
witch bugs me.. When I create a XML witch references the main schema
above it gets the following start: <n:AD-DA_Converters
xmlns:n="COSTypes" ..... >
Why do this 'n' sneak in? And can I get rid of it?

I also tried to make the main schema to have the following start:
<xs:schema targetNamespace="COSTypes"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:cos="COSTypes">
But then I get 'cos' instead of 'n' in the XMLs.

So, do I have live with this little prefix, or is there some way to get
rid of it..? I didn't want it to affect the XML files that I've
seperated the definitions into more XSD-files...

Best regards,
Stian

Jul 20 '05 #3


stiank81 wrote:

I see everywhere that the target namespace and things like that is
defined as a web adress... Like in the w3.org examples:
<schema targetNamespace="http://www.example.com/IPO"..... and so on..

Does this have to be a web adress?
It should be a URI but it does not have to be one pointing to any
resource on the web, URLs are just used to have globally unique names.

When I create a XML witch references the main schema
above it gets the following start: <n:AD-DA_Converters
xmlns:n="COSTypes" ..... >
Why do this 'n' sneak in? And can I get rid of it?


Well how do you "create a XML"? Are you using any tools?
Of course if the elements are in a namespace then you need to declare
one in the XML instance document but you can use a default namespace
<D-DA_Converters xmlns="COSTypes">
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #4
Okay.
I use Altova XMLspy to create the XML files.. And it generates the
namespace, 'n', automatically. I now use the default namespace in both
XML-schemas, and when I try to remove the 'n' to use a default
namespace in the XML it doesn't validate - with the following error:
"This file is not valid:
Unexpected element 'AD-DA_Converter' in element 'COSTypes'. Expected
AD-DA_Converters."

--> but the XML should be correct according to the definitions in the
XSD.. The root element is still "AD-DA_Converters", witch is what it
asks for here.. But even when I put this element here I get the same
error, where it says "AD-DA_Converters" unexpected, AD-DA_Converters
expected.. Witch really doesn't make much sense.. I don't know if the
validator is bad or what?.. But apparently there is something wrong...

-Stian

Jul 20 '05 #5

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

Similar topics

0
by: C. M. Sperberg-McQueen | last post by:
wooks (wookiz@hotmail.com) wrote: > <?xml version='1.0'?> > <userlogin xmlns="urn:faster:userlogin" > xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'> > <login>mick</login> > ...
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...
3
by: Davide Bedin | last post by:
I have a "library" schema with the simple and complex types I commonly use in other schemas and then several other schemas, maybe created by other developers, that import/include the library...
8
by: Poonam | last post by:
Hi, Can some one please help me with (or point me to) a very simple but working code sample that shows how to import XML Schema. I have tried many samples out there on internet but nothing seems...
0
by: Deep Purple | last post by:
I started with the following error... ------------------------------------------------------- An error occured while loading the schema with TargetNamespace 'http://www.w3.org/2001/XMLSchema'...
0
by: comic_rage | last post by:
Hi, I am trying to add the following line to my xml schema xsd file <xsd:include schemaLocation="../../../Common/datatypes.xsd"/> Here is my code XmlSchemaInclude include = new...
4
by: bibsoconner | last post by:
Hi, I hope someone can please help me. I'm having a lot of trouble with schema files in .NET. I have produced a very simple example that uses "include" to include other schema files. It all...
1
by: Wallace | last post by:
Hi all, I have a problem on validating a xml fragment using a single namespace schema which spread across multiple schema files using include in the master schema file. No matter how I change...
2
by: Simon | last post by:
I want to split a xml schema in two xml schema files where the first file has general schemas and the other part has specific schemas. The general schema can the be used by other schemas (written...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.