second namespace in same schema

Z

Zombie

Hi all,
I wish to create a namespace other than the default one.
Let's say, the Schema looks like:

-----------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:d="http://www.geodesy.org/dam"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="River">
<xs:complexType>
<xs:sequence>
<xs:element name="Length" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
-----------------------------------------------------------------------

Now, I wish that a new element is added to this schema which belongs
to another namespace (and not the default one). Is this possible?



Thanks.
 
M

Martin Honnen

Zombie wrote:

I wish to create a namespace other than the default one.
Let's say, the Schema looks like:

I guess you want
targetNamespace="http://www.geodesy.org/dam"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="River">
<xs:complexType>
<xs:sequence>
<xs:element name="Length" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

You need a second schema for the second namespace (make sure you set the
targetNamespace there), then you can use <xs:import> to import that
schema into the first schema.
 
Z

Zombie

Martin Honnen said:
Zombie wrote:



I guess you want
targetNamespace="http://www.geodesy.org/dam"
[snip] [snip] [snip]
You need a second schema for the second namespace (make sure you set the
targetNamespace there), then you can use <xs:import> to import that
schema into the first schema.


I will rephrase my query and put it in the proper context: I wish to
create an XML schema that successfully validates an XML file
containing any new unknown elements. Assume that the schema has only
"Name" and "Address" elements declared. If the XML contains the
elements "Name", "Address" _and_ "Age", then only "Name" and "Address"
should get validated and "Age" should be ignored.

I have found a way to do this by using <xs:any namespace="##other">.
However, I am facing some problems with it. Here is the detailed
decription:

I have a schema (schema0)to which new elements get added over time (no
elements are ever removed). These different schemas are called
schema0, schema1 etc. Corresponding to each of these, I will have XML
files xml0, xml1 etc. I want xml1 to get successfuly validated against
schema1 as well as schem0. Similarly, xml2 should get validated
against schema2, schema1 and schema0...and so on.
To achieve this, I use <xs:any namespace="##other"> in schema0.
<<schema0 and xml1 are given at the end>>

The trick is to use a namespace (xmlns:d) for the new element
"<d:Age>" in xml1. Due to <xs:any namespace="##other">,schema0 allows
this unknown element.
Now, the problem is that I have to validate xml1 against schema1 too.
Schema1 is extended from schema0 by defining another element "Age" in
namespace "d".
The constraint here is that the whole of the schema1 should be
contained in a single file. How do I declare this new element and
namespace along with schema0?
Clear as mud? :D

Thanks for your time!



schema0:
----------------------------------------------------------------------
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="River">
<xs:complexType>
<xs:sequence>
<xs:element name="Name" type="xs:string"/>
<xs:any namespace="##other"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
---------------------------------------------------------------------


xml1:
---------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<River xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="D:\schema1.xsd"
xmlns:d="http://www.geodesy.org/dam" >
<Name>The Three Gorges Dam</Name>
<d:Age>12</d:Age>
</River>
---------------------------------------------------------------------
 

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

Members online

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top