W3C home > Mailing lists > Public > xmlschema-dev@w3.org > January 2006

Re: Hiding namespace prefixes in the instance document

From: George Cristian Bina <george@oxygenxml.com>
Date: Mon, 09 Jan 2006 11:38:06 +0200
Message-ID: <43C22EFE.5040509@oxygenxml.com>
To: Antti Sissonen <antti_sissonen@hotmail.com>
CC: mike@saxonica.com, xmlschema-dev@w3.org

Hello Antti,

 From your message it looks like you want to have the elements inside 
the same namespace then, yes, you should include that schema to have 
those elements defined in the same target namespace.
If you do not want a namespace declaration for the root element then you 
will have everything in no namespace and all you have to do is to not 
specify the target namespace for any schema document.
If you want a namespace for the root element then you can still leave 
the target namespace not specified in the included schema documents and 
their components will automatically inherit the target namespace from 
the including schema (the chameleon effect that you mentioned). So for 
instance having the following schemas:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
targetNamespace="schema_namespace" xmlns="schema_namespace">
     <xs:include schemaLocation="antti-common.xsd"/>
     <xs:element name="Schema">
                 <xs:element ref="MaterialBatchIdentifier"/>

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
     <xs:element name="MaterialBatchIdentifier"/>

will give you a document like:

<?xml version="1.0" encoding="UTF-8"?>
<Schema xmlns="schema_namespace">

That is the MaterialBatchIdentifier element is inside the 
schema_namespace namespace.

Best Regards,
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger

Antti Sissonen wrote:
> I wouldn't want to sound too picky about this, but what I expect from 
> the xml instance is readability. Having a prefix has an effect on 
> parsing. What you suggest below, declaring the namespaces as attributes 
> removes that problem but it still looks quite confusing to a business 
> person possibly receiving the message. So how do I set up my case so 
> that the element looks like
> <MaterialBatchIdentifier>, not
> <common:MaterialBatchIdentifier> or
> <MaterialBatchIdentifier xmlns="commonNamespace">?
> Is there some way to do this so that the common schema has its own 
> separate target namespace or do I just switch to include? What would be 
> the downsides of that? Not many sources encourage the use of chameleon, 
> that's why I'm doubtful.
> _________________________________________
> Antti Sissonen [Antti_Sissonen@hotmail.com]
>> You can write documents that contain elements from multiple namespaces 
>> without using prefixes, there is no limitation to declare only one 
>> namespace as default namespace. So you can have:
>> <Schema xmlns="schemaNamespace">
>>   <Aggregate xmlns="aggregateNamespace">
>>     <MaterialBatchIdentifier xmlns="commonNamespace">
>> and so on...
>> Import keeps the same target namespace for the imported components. 
>> Include includes components from a different target namespace. Again, 
>> it depends what namespace you want for your elements, that is what you 
>> should clarify first then you should think how to write the schema for 
>> that.
>> Regards,
>> George
>> ---------------------------------------------------------------------
>> George Cristian Bina
>> <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
>> http://www.oxygenxml.com
>> Antti Sissonen wrote:
>>> What I meant was not having namespace prefixes in the instance 
>>> document since in this particular case the xml instance presents 
>>> business content and the element naming should be exact.
>>> So if I am using a common element coming from a common component 
>>> schema it should look like this:
>>> <Schema>
>>>  <Aggregate>
>>>    <MaterialBatchIdentifier>
>>>    ...
>>> instead of:
>>> <Schema>
>>>  <Aggregate>
>>>    <common:MaterialBatchIdentifier>
>>> Does that help?
>>> I've understood that I can get rid of prefixes by using the correct 
>>> design (venetian blind) and the default namespace definition 
>>> (xmlns="foo", not xmlns:foo="foo") if only one namespace is declared 
>>> for the instance. But then if I'd like to have a separate namespace 
>>> for the common components I run out of options. Thus, I've concluded 
>>> that maybe I just have to have common component schema in no 
>>> namespace and use include to have it available (chameleon).
>>> If the idea of the schema architecture is to assure that the same 
>>> name will not be used for different things the chameleon design would 
>>> support/force it. What is it that I'd lose if I switch from import to 
>>> include?
>>> Rgrds,
>>> Antti
>>>> > I have a schema that imports another one. I'm trying to keep
>>>> > the namespace
>>>> > prefixes hidden in the xml instance
>>>> Sorry, I've no idea what you mean. What does a "hidden prefix" look 
>>>> like?
>>>> Michael Kay
>>>> http://www.saxonica.com/
Received on Monday, 9 January 2006 09:34:54 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:15:32 UTC