Question about tag and value

Discussion in 'XML' started by mittra@juno.com, Nov 5, 2007.

  1. Guest

    Hello All,

    I am a newbie to XML. I have the following question: how do I express
    something in XML when the subsequent tag structures depends on the
    value of a preceeding tag?

    For example, when TAG2 has a value of 1, then TAG3 exists.

    <TAG1>
    <TAG2>1</TAG2>
    <TAG3>some_value</TAG3>
    </TAG1>

    But when TAG2 has a value of 2, then TAG4 exists.

    <TAG1>
    <TAG2>2</TAG2>
    <TAG4>some_value2</TAG4>
    </TAG1>

    Can the above two be combined into a single structure for TAG1?

    Thanks for your insight.
     
    , Nov 5, 2007
    #1
    1. Advertising

  2. wrote:
    > I am a newbie to XML. I have the following question: how do I express
    > something in XML when the subsequent tag structures depends on the
    > value of a preceeding tag?


    Neither DTDs nor XML Schema allow you to use the value of an element or
    attribute to constrain the presence or another -- with the exception of
    the xsi:type attribute; see a good XML Schema tutorial (or a great deal
    of recent discussion in this very newsgroup) for details of how to use
    that sub-typing feature.

    You *can* structure things so the presence or absence of your <TAG2>
    element gates whether TAG3 or TAG4 was expected after it, by writing the
    appropriate content models in your DTD or Schema.

    Or you can enforce the cross-constraint in your application rather than
    expecting the document formalism to do it all. Remember, neither DTDs
    nor schemas are intended to capture all the semantics of a document, and
    some checking will always have to be done by the application --
    vaidation only provides an initial layer and some "machine-readable
    documentation" of what's expected.

    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
     
    Joseph Kesselman, Nov 6, 2007
    #2
    1. Advertising

  3. Joseph Kesselman wrote:
    > vaidation only provides an initial layer and some "machine-readable
    > documentation" of what's expected.


    Putting it another way -- Validity, if you're enforcing it, documents
    things that are Necessary for a correct document, but may not enumerate
    everything that is Sufficient for it to be correct.


    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
     
    Joseph Kesselman, Nov 6, 2007
    #3
  4. Guest

    On Nov 5, 4:29 pm, Joseph Kesselman <>
    wrote:
    > wrote:
    > > I am a newbie to XML. I have the following question: how do I express
    > > something in XML when the subsequent tag structures depends on the
    > > value of a preceeding tag?

    >
    > Neither DTDs nor XML Schema allow you to use the value of an element or
    > attribute to constrain the presence or another -- with the exception of
    > the xsi:type attribute; see a good XML Schema tutorial (or a great deal
    > of recent discussion in this very newsgroup) for details of how to use
    > that sub-typing feature.
    >
    > You *can* structure things so the presence or absence of your <TAG2>
    > element gates whether TAG3 or TAG4 was expected after it, by writing the
    > appropriate content models in your DTD or Schema.
    >
    > Or you can enforce the cross-constraint in your application rather than
    > expecting the document formalism to do it all. Remember, neither DTDs
    > nor schemas are intended to capture all the semantics of a document, and
    > some checking will always have to be done by the application --
    > vaidation only provides an initial layer and some "machine-readable
    > documentation" of what's expected.
    >
    > --
    > Joe Kesselman / Beware the fury of a patient man. -- John Dryden


    Thanks. I will look into XML Schema tutorial.

    However, from your respnse it seems I might not have communicated the
    objective behind doing this. While I can enforce the check of the
    subsequent tag structure (TAG3 or TAG4) in the application domain, the
    primary objective is to define *one* XML structure that (based on
    TAG2) defines the *entire* structure. This will be akin to saying, in
    this example,

    if (TAG2 value is 1) then
    <TAG3>some_value</TAG3>
    else
    <TAG4>some_value2</TAG4>

    Perhaps, XML Schema does it?
     
    , Nov 6, 2007
    #4
  5. wrote:
    > if (TAG2 value is 1) then
    > <TAG3>some_value</TAG3>
    > else
    > <TAG4>some_value2</TAG4>


    Neither XML Schema nor DTDs can express that constraint, except by using
    xsi:type. Some of the less-widely-supported schema languages can (I
    think both RelaxNG and Schematron can do this) -- but then you have the
    problem of whether your users will accept those solutions.

    Again: The simplest answer is to fix it in documentation and in
    application code.


    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
     
    Joe Kesselman, Nov 6, 2007
    #5
  6. hi,

    a écrit :
    >
    > if (TAG2 value is 1) then
    > <TAG3>some_value</TAG3>
    > else
    > <TAG4>some_value2</TAG4>
    >
    > Perhaps, XML Schema does it?
    >


    this is exactly the way the Active Schema Language works : you can
    define dynamically the content model that suits your needs, potentially
    with the help of if-then-else statements

    although ASL is experimental, it is implemented and works fine : you can
    use it for your own needs if you don't have to share your own schemas
    with third-party users ; ASL will allow you to express much more complex
    constraints than legacy schema technologies can (DTD, W3C XML Schema,
    RelaxNG, Schematron)

    the implementation :
    http://reflex.gforge.inria.fr/
    the specification :
    http://ns.inria.fr/active-tags/active-schema/active-schema.html
    some tutorials :
    http://reflex.gforge.inria.fr/tutorial-schemas.html

    if you are new to XML, you'll have to understand namespaces in XML and
    learn XPath before (which are widely used in XML technologies)

    some courses :
    http://disc.inria.fr/perso/philippe.poulard/cours/01c-xml-namespaces.pdf
    http://disc.inria.fr/perso/philippe.poulard/cours/04-xml-xpath.pdf
    ....if you are new to french, you'll have to learn french before :)

    --
    Cordialement,

    ///
    (. .)
    --------ooO--(_)--Ooo--------
    | Philippe Poulard |
    -----------------------------
    http://reflex.gforge.inria.fr/
    Have the RefleX !
     
    Philippe Poulard, Nov 6, 2007
    #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. shruds
    Replies:
    1
    Views:
    834
    John C. Bollinger
    Jan 27, 2006
  2. su
    Replies:
    2
    Views:
    1,791
  3. Replies:
    4
    Views:
    443
  4. Replies:
    7
    Views:
    501
    Max Erickson
    Mar 26, 2007
  5. P
    Replies:
    7
    Views:
    141
    Tad McClellan
    Jan 12, 2007
Loading...

Share This Page