2 namespaces in 1 schema

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

  1. Zombie

    Zombie Guest

    Hi,
    Can I have 2 namespaces in the same XML schema?
    In the schema, I wish to declare elements such that some of them
    belong to one namespace and others belong to a second namespace. Is
    this possible? Note that both the namespaces should be in the same
    schema and same xsd file. Could somebody provide a small snippet on
    how to do this?

    Thanks for your time.
     
    Zombie, Aug 18, 2004
    #1
    1. Advertising

  2. Zombie wrote:


    > Can I have 2 namespaces in the same XML schema?


    You need at least one schema to define elements for each namespace but
    of course a schema for one namespace can import a schema for another
    namespace and then reference elements from the other namespace.




    --

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

  3. Zombie

    Zombie Guest

    Martin Honnen <> wrote in message news:<4123435a$0$7317$-online.net>...
    > Zombie wrote:
    >
    >
    > > Can I have 2 namespaces in the same XML schema?

    >
    > You need at least one schema to define elements for each namespace but
    > of course a schema for one namespace can import a schema for another
    > namespace and then reference elements from the other namespace.


    Do you mean to say that 1 schema file can contain only 1 namespace?
    Actually, 'import' is exactly what I want to avoid. That is why in the
    OP, I explicitly mentioned that I want 1 schema in 1 xsd file
    containing 2 namespaces.
    Any way to do that?

    Thanks much.
     
    Zombie, Aug 19, 2004
    #3
  4. Zombie

    Abhinav Guest

    Zombie wrote:
    > Martin Honnen <> wrote in message news:<4123435a$0$7317$-online.net>...
    >
    >>Zombie wrote:
    >>
    >>
    >>
    >>>Can I have 2 namespaces in the same XML schema?

    >>
    >>You need at least one schema to define elements for each namespace but
    >>of course a schema for one namespace can import a schema for another
    >>namespace and then reference elements from the other namespace.

    >
    >
    > Do you mean to say that 1 schema file can contain only 1 namespace?
    > Actually, 'import' is exactly what I want to avoid. That is why in the
    > OP, I explicitly mentioned that I want 1 schema in 1 xsd file
    > containing 2 namespaces.
    > Any way to do that?
    >


    Does this help ?

    (This is an example given to me by Zafar Abbas at the newsgroup
    microsoft.public.xml. Google for "Schema - Definition for checking part of
    schema?")

    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="a">
    <xs:complexType>
    <xs:sequence>
    <xs:group ref = "allowAny"/>
    <xs:element name="aa" />
    <xs:group ref = "allowAny"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>

    <xs:group name="allowAny">
    <xs:sequence>
    <xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other" />
    </xs:sequence>
    </xs:group>

    </xs:schema>

    The following xml will be valid according to it:

    <a xmlns:ns="ns">
    <aa>
    </aa>

    <ns:bb></ns:bb>
    <ns:cc></ns:cc>

    </a>

    Regards

    --

    Abhinav
     
    Abhinav, Aug 19, 2004
    #4
  5. Zombie wrote:

    > Martin Honnen <> wrote in message news:<4123435a$0$7317$-online.net>...
    >
    >>Zombie wrote:
    >>
    >>
    >>
    >>>Can I have 2 namespaces in the same XML schema?

    >>
    >>You need at least one schema to define elements for each namespace but
    >>of course a schema for one namespace can import a schema for another
    >>namespace and then reference elements from the other namespace.

    >
    >
    > Do you mean to say that 1 schema file can contain only 1 namespace?


    It depends on what you mean by "contain". I clearly said that you need
    one schema to define the elements for one namespace but that you need to
    import the definitions of the schema for a second namespace.

    > Actually, 'import' is exactly what I want to avoid. That is why in the
    > OP, I explicitly mentioned that I want 1 schema in 1 xsd file
    > containing 2 namespaces.
    > Any way to do that?


    No, if you want to validate all elements and you have elements in
    differerent namespaces then you need to have one schema for every
    namespace you want to define elements in.

    The only thing you can do is skip validation for elements in one
    namespace with
    <xs:any>

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Aug 19, 2004
    #5
  6. Zombie

    Zombie Guest

    Abhinav <> wrote in message news:<P3_Uc.13$>...
    > Zombie wrote:
    > > Martin Honnen <> wrote in message news:<4123435a$0$7317$-online.net>...
    > >
    > >>Zombie wrote:
    > >>
    > >>
    > >>
    > >>>Can I have 2 namespaces in the same XML schema?
    > >>
    > >>You need at least one schema to define elements for each namespace but
    > >>of course a schema for one namespace can import a schema for another
    > >>namespace and then reference elements from the other namespace.

    > >
    > >
    > > Do you mean to say that 1 schema file can contain only 1 namespace?
    > > Actually, 'import' is exactly what I want to avoid. That is why in the
    > > OP, I explicitly mentioned that I want 1 schema in 1 xsd file
    > > containing 2 namespaces.
    > > Any way to do that?
    > >

    >
    > Does this help ?
    >
    > (This is an example given to me by Zafar Abbas at the newsgroup
    > microsoft.public.xml. Google for "Schema - Definition for checking part of
    > schema?")
    >
    > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    > <xs:element name="a">
    > <xs:complexType>
    > <xs:sequence>
    > <xs:group ref = "allowAny"/>
    > <xs:element name="aa" />
    > <xs:group ref = "allowAny"/>
    > </xs:sequence>
    > </xs:complexType>
    > </xs:element>
    >
    > <xs:group name="allowAny">
    > <xs:sequence>
    > <xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other" />
    > </xs:sequence>
    > </xs:group>
    >
    > </xs:schema>
    >
    > The following xml will be valid according to it:
    >
    > <a xmlns:ns="ns">
    > <aa>
    > </aa>
    >
    > <ns:bb></ns:bb>
    > <ns:cc></ns:cc>
    >
    > </a>
    >
    > Regards


    Abhinav, thanks for your effort. Actually, my problem starts right
    after this.
    Now, I wish to come up with a second schema that will define the "bb"
    and "cc" elements so that the above xml gets validated against this
    new schema (bb and cc should also get validated now). As you can see,
    in the xml, "bb" and "cc" are in a new namespace. So, in the new
    schema too, they need to be defined in a new namespace. And that is
    exactly what I am unable to do.
    I hope you understand my problem.

    Thanks again.
     
    Zombie, Aug 19, 2004
    #6
    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,640
    Markus
    Nov 23, 2005
  2. Miel Bronneberg

    DTDs, schema's and namespaces

    Miel Bronneberg, Sep 30, 2003, in forum: XML
    Replies:
    2
    Views:
    378
    Miel Bronneberg
    Sep 30, 2003
  3. PA
    Replies:
    0
    Views:
    398
  4. Ingrid
    Replies:
    0
    Views:
    361
    Ingrid
    Aug 19, 2004
  5. Stanimir Stamenkov
    Replies:
    3
    Views:
    1,312
    Stanimir Stamenkov
    Apr 25, 2005
Loading...

Share This Page