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 09:53:34 +1000
Message-ID: <3BB26A7E.26370973@allette.com.au>
To: Frank VAN LINGEN <Frank.van.Lingen@cern.ch>
CC: xmlschema-dev@w3.org
Hi Frank,

> I am trying to use namespaces within xmlschema. The idea is that editors
> of instances of this schema do not have to use prefixes for namespaces,
> since these are already described in the schema. However, if I try to do
> this, it turns out that I stil have to use prefixes for namespaces in my
> instance document. Below is a small example (part
> of schema and instance document). In the schema I import a schema related
> to a namespace.
> Within the type definition of materialfraction I use this namespace to
> indicate that it should use a structure defined in the schema associated
> with this namespace.
> I thought this would give enough information not to use namespaces in the
> instance document. However, I still have to declare a namespace for this
> element (see instance part).
> Is there a way to use namespaces in schemas and avoid them in instance
> documents?

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.

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 19:47:29 UTC

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