second namespace in same schema

Discussion in 'XML' started by Zombie, Aug 13, 2004.

  1. Zombie

    Zombie Guest

    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.
     
    Zombie, Aug 13, 2004
    #1
    1. Advertising

  2. Zombie wrote:


    > 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"


    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>
    > -----------------------------------------------------------------------
    >
    > 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?


    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.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Aug 13, 2004
    #2
    1. Advertising

  3. Zombie

    Zombie Guest

    Martin Honnen <> wrote in message news:<411cf37a$>...
    > Zombie wrote:
    >
    >
    > > 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"

    >
    > I guess you want
    > targetNamespace="http://www.geodesy.org/dam"
    >

    [snip] [snip] [snip]

    > > -----------------------------------------------------------------------
    > >
    > > 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?

    >
    > 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>
    ---------------------------------------------------------------------
     
    Zombie, Aug 16, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Markus
    Replies:
    1
    Views:
    1,663
    Markus
    Nov 23, 2005
  2. Stanimir Stamenkov
    Replies:
    3
    Views:
    1,328
    Stanimir Stamenkov
    Apr 25, 2005
  3. Replies:
    1
    Views:
    543
    George Bina
    Jul 20, 2006
  4. Jacek Generowicz
    Replies:
    1
    Views:
    399
    Daniel Dittmar
    Apr 8, 2004
  5. yelipolok
    Replies:
    4
    Views:
    289
    John W. Krahn
    Jan 27, 2010
Loading...

Share This Page