Xml Schema namespace

This should cover W3C XML Schema, Relax NG and DTD related problems.
Radu
Posts: 8992
Joined: Fri Jul 09, 2004 5:18 pm

Re: Xml Schema namespace

Post by Radu »

Dear Matrick,

There is a W3C standard for XML Schema which defines how XML Schemas are constructed and how they are referenced from the XML documents. There is a committee which created that standard, we (the Oxygen XML team) are/were not part of that committee, we just implement the editing/validation functionality on top of that standard.
With this in mind, please see some replies below for your queries:
1) I realize namespaces are a means of differentiating between different schemas/vocabularies specified using XML Schema, but I don’t understand why it’s a good idea that a namespace ( for which the schema is developing a vocabulary ) is specified within the schema itself ( via targetNamespace attribute ).
I think the main idea is to restrict the choices for people creating the XML documents. A company designs the XML Schema, they choose the target namespace, they set that inside the XML Schema. All people or processes which create XML documents based on that schema are forced to use that target namespace in the XML instances.
This is specific not only to the XML Schema standard, but also to the Relax NG standard as well.
a) Wouldn’t it be better if we were able to instead associate particular namespace with particular vocabulary/schema within instance documents? That way those writing instance documents would have a complete freedom to associate a schema with whichever namespace name they’d desire?!
Same as above.
b) Only benefit I see in the schema specifying a target namespace is that its creators have an option to put a document at the end of namespace that can describe the elements of that namespace ( assuming schema uses URL for a namespace ). Are there also other benefits?
Actually you can combine using xsd:import multiple schemas from multiple namespaces and use them for XML editing and validation.
So an XML Schema has a target namespace specified but it uses xsd:import to import other XML Schemas which have other target namespaces specified. And the XML document can be created having multiple elements from different namespaces.
2) If a schema has no targetNamespace, you must refer ( within instance document ) to the particular schema using the noNamespaceSchemaLocation attribute instead of schemaLocation attribute.
The "schemaLocation" requires its values to be pairs of "namespace schemaLocation", by the way they can be multiple pairs of like"xsi:schemaLocation="namespace1 schemaLocation1 namespace2 schemaLocation2"". The "noNamespaceSchemaLocation" takes a single value which is the reference to the XML Schema.
Wouldn’t it be simpler if instead document instance would just specify the location of the schema and let the XML Schema validator figure out whether or not schema specifies a targetNamespace?
I think this flexibility which in 99.9% of cases is not needed derives from the fact that inside an XML Schema you can have multiple xsd:imports to XML Schemas having other target namespaces. So when you refer to an XML Schema using xsi:schemaLocation you also specify the namespace of the elements you are interested in.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com