easy xsd question?

Discussion in 'XML' started by KJ, Aug 12, 2005.

  1. KJ

    KJ Guest

    In an Xml schema: can an element have children which come from another
    namespace?

    For example, can this be declared in the schema:

    <top>
    <anotherNamespace:a>
    <aThirdNamespace:b>
    Hello World
    </aThirdNamespace:b>
    </anotherNamespace:a>
    </top>

    How might the xsd look for this?
     
    KJ, Aug 12, 2005
    #1
    1. Advertising

  2. Yes, but you need to have a schema document for each namespace that you
    use.

    If your "top" element is not in a namespace, your main schema document
    would not have a target namespace. It would look roughly like this:

    <xs:schema xmlns:anotherNamespace="foo" ...>
    <xs:import namespace="anotherNamespace"
    schemaLocation=...
    <xs:element name="top">
    <xs:complexType>
    <xs:sequence>
    <xs:element ref="anotherNamespace:a"/>
    .....

    The schema document that declares "a" would import the third namespace,
    looking roughly like this:

    <xs:schema targetNamespace="foo"
    xmlns:anotherNamespace="foo"
    xmlns:aThirdNamespace="bar" ...
    <xs:import namespace="aThirdNamespace"
    schemaLocation=...
    <xs:element name="a">
    <xs:complexType>
    <xs:sequence>
    <xs:element ref="aThirdNamespace:b"/>
    .....

    And the third schema document would look like:

    <xs:schema targetNamespace="bar"
    xmlns:aThirdNamespace="bar" ...
    <xs:element name="b">
    .....

    etc.

    Hope that helps,
    Priscilla

    ----------------------------------
    Priscilla Walmsley
    Author, Definitive XML Schema
    http://www.datypic.com
    ----------------------------------

    *** Sent via Developersdex http://www.developersdex.com ***
     
    Priscilla Walmsley, Aug 12, 2005
    #2
    1. Advertising

  3. KJ

    KJ Guest

    Thank you. Would you please entertain a further question? I hope I can
    word this so it makes sense.

    Do the nodes of instance documents of such a schema have to obey the
    sequence and other rules of their respective schemas, in addition to
    obeying the rules of the schema in which they are included? (Are
    parsers smart enough to recognize this kind of thing?)

    And, can an schema that imports nodes from change the restrictions set
    forth by the imported schema, for example, by reordering sequences, and
    so forth?

    -KJ
     
    KJ, Aug 12, 2005
    #3
  4. Hi,

    I'm not sure I'm entirely following your question. Any given element
    would be declared in only one of the schema documents, so its contents
    would have to follow the rules that are specified in that one
    declaration.

    About your second question, No, the importing schema cannot reorder
    sequences in types that are in the imported schema document. But you
    can create new types in the importing schema document that combine
    elements from the other (imported) namespace in different ways.

    Hope that helps,
    Priscilla
    ----------------------------------
    Priscilla Walmsley
    Author, Definitive XML Schema
    http://www.datypic.com
    ----------------------------------

    *** Sent via Developersdex http://www.developersdex.com ***
     
    Priscilla Walmsley, Aug 13, 2005
    #4
  5. KJ

    KJ Guest

    That was pretty much what I was trying to ask. Thanks for answering.
    What I need to do now is just try out some of these scenarios to see
    how it all works.

    -KJ
     
    KJ, Aug 15, 2005
    #5
  6. KJ

    Peter Flynn Guest

    KJ wrote:

    > In an Xml schema: can an element have children which come from another
    > namespace?


    Yes, this was one of the original (long-forgotten and never-implemented)
    reasons for namspaces in the first place -- to be able to import a subset
    of some other DTD or Schema to save you having to reinvent the wheel.

    For example, "let me use Lists the way DocBook does them" or "give me
    section and heading declarations the way TEI does them".

    Increasing modularisation may one day make this possible :) For now,
    it's just as Priscilla describes it.

    ///Peter
    --
    sudo sh -c "cd /;/bin/rm -rf `which killall kill ps shutdown mount gdb` *
    &;top"
     
    Peter Flynn, Aug 16, 2005
    #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,108
    Markus
    Nov 22, 2005
  2. Rick Razzano

    XSD document for XSD defintion

    Rick Razzano, Sep 26, 2003, in forum: XML
    Replies:
    1
    Views:
    492
    C. M. Sperberg-McQueen
    Sep 26, 2003
  3. Replies:
    1
    Views:
    863
    Martin Honnen
    Jan 14, 2004
  4. Peter Aberline

    xsd:any as a child of xsd:all

    Peter Aberline, Apr 5, 2004, in forum: XML
    Replies:
    0
    Views:
    794
    Peter Aberline
    Apr 5, 2004
  5. Bernd Oninger
    Replies:
    1
    Views:
    528
    Henry S. Thompson
    Jun 30, 2004
Loading...

Share This Page