XML schema - Make xsd include another xsd

S

stiank81

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
 
M

Martin Honnen

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>
 
S

stiank81

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
 
M

Martin Honnen

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">
 
S

stiank81

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
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top