W3C home > Mailing lists > Public > xmlschema-dev@w3.org > September 2001

Re: using namespaces in xmlschema

From: Eddie Robertsson <eddie@allette.com.au>
Date: Thu, 27 Sep 2001 10:12:30 +1000
Message-ID: <3BB26EED.59A887FD@allette.com.au>
To: Frank VAN LINGEN <Frank.van.Lingen@cern.ch>, xmlschema-dev@w3.org
> If you want to use namespaces (i.e you have a tragetNamespace for your
> schema) then your instance document must use namespaces as well. However,
> you can still use the default namespace declaration in your instance
> document which means you don't have to prefix your elements IF you only use
> ONE namespace throughout your instance document. In your case below you use
> more than one namespace that means at least one of the namespaces must be
> prefixed.
> You can workaround this by declaring all your elements in your main schema
> (http://www.cern.ch/DDLMaterial) and then let the schema you import
> (http://www.cern.ch/DDLReference) only define the types you want to use. The
> problem arises when this including schema declares elements because that
> means these elements will be declared in the http://www.cern.ch/DDLReference
> namespace and must then use this namespace in the instance document as well.

I just realised that what I wrote above is probably only true when declaring
global elements in the imported schema. You probably can get away with local
element declarations as long as you use elementFormDefault="unqualified". There
is more information about this on the best practice page [1] under the topic
"Hide (Localize) Versus Expose Namespaces"

[1] http://www.xfront.com/BestPracticesHomepage.html

Cheers,
/Eddie

>
>
> Hope this helps,
> /Eddie
>
> > -----snippet of an xml schema I use:
> >
> > <?xml version="1.0"?>
> > <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> >             targetNamespace="http://www.cern.ch/DDLMaterial"
> >             xmlns="http://www.cern.ch/DDLMaterial"
> >             xmlns:DDLReference="http://www.cern.ch/DDLReference"
> >             elementFormDefault="unqualified">
> >
> > <!-- Importing  -->
> >
> > <xsd:import namespace="http://www.cern.ch/DDLReference"
> >             schemaLocation="DDLReference.xsd" />
> >
> > <!-- Element definitions -->
> >
> > <xsd:element name="MaterialFraction" type="MaterialFractionType"/>
> >
> > <!-- Type definitions -->
> >
> > <xsd:complexType name="MaterialFractionType">
> >   <xsd:sequence>
> >       <xsd:element ref="DDLReference:rMaterial" minOccurs='1'
> > maxOccurs='1'/>
> >   </xsd:sequence>
> >   <xsd:attributeGroup ref="MaterialFractionAttributes"/>
> > </xsd:complexType>
> >
> > <!-- Attribute definitions -->
> >
> > <xsd:attributeGroup name="MaterialFractionAttributes">
> >    <xsd:attribute name="fraction" type="xsd:float" use="required"/>
> > </xsd:attributeGroup>
> >
> > </xsd:schema>
> >
> > ----------------------snippet of instance document based on this schema
> > <?xml version="1.0"?>
> > <CompositeMaterial xmlns="http://www.cern.ch/DDLMaterial"
> >
> > xmlns:DDLReference="http://www.cern.ch/DDLReference"
> >
> > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> >                         xsi:schemaLocation=
> >                             "http://www.cern.ch/DDLMaterial
> > DDLMaterial.xsd
> >                             http://www.cern.ch/DDLReference
> > DDLReference.xsd"
> >                         name="testmat" ID="12" symbol="te"
> > method="mixture by weight">
> >    <Density value="1.2" units="g/cm^3"/>
> >    <MaterialFraction fraction="0.4">
> >        <DDLReference:rMaterial name="testref"
> > url="http://www.cern.ch/somewhere.xml"/>
> >    </MaterialFraction>
> >    <MaterialFraction fraction="0.3">
> >        <DDLReference:rMaterial name="testref1"
> > url="http://www.cern.ch/somewhere.xml"/>
> >    </MaterialFraction>
> > </CompositeMaterial>
> >
> > ----------------------------------
> >
> > Frank van Lingen
Received on Wednesday, 26 September 2001 20:05:44 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:55:53 UTC