Simple question on XML Schema

Discussion in 'XML' started by Nimmi Srivastav, Mar 18, 2010.

  1. Greetings,

    I have two newbie questions.

    1) Using XML Schema, how can I describe an XML document in which the
    root element is either A or B? Also, using DTD, how can the same be
    achieved?

    2) In an XML driven messaging system, is it a good design practice to
    use XML documents with different root elements to indicate the message
    version information? For example, the root element can be Ver1 or
    Ver2. If the recipient receives XML content with root element Ver1,
    it processes it as a version 1 message and if the recipient receives
    XML content with root element Ver2, it processes it as a version 2
    message. The structure of Ver1 message can be substantially different
    from the structure of the Ver2 message.

    Thanks,
    Nimmi
     
    Nimmi Srivastav, Mar 18, 2010
    #1
    1. Advertisements

  2. I don't think DTD can do that.
    As for a schema, any top level element you define in your schema can
    serve as a root element so when you do e.g.

    <xs:schema
    xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:element name="A">
    <xs:complexType>
    ...
    </xs:complexType>
    </xs:element>

    <xs:element name="B">
    <xs:complexType>
    ...
    </xs:complexType>
    </xs:element>

    </xs:schema>

    then you allow 'A' or 'B' as a root element.
     
    Martin Honnen, Mar 18, 2010
    #2
    1. Advertisements

  3. Nimmi Srivastav

    Peter Flynn Guest

    In a DTD, it's the same concent as in a Schema, in that any top-level
    element type (one that is not in the content model of any other element
    type) could be assumed to be a root element type, although the SGML
    standard doesn't specify whether you have to make that assumption or
    not, because in a DTD, *any* element type can be a root element type, eg

    <!DOCTYPE td SYSTEM "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <td></td>

    ///Peter
     
    Peter Flynn, Mar 20, 2010
    #3
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.