How do I express this constraint with RELAX NG?

Discussion in 'XML' started by James McComb, Nov 19, 2003.

  1. James McComb

    James McComb Guest

    Please, can someone tell me how I can express
    this constraint using Relax NG?

    I want these documents to be valid:

    <memo>
    <code>WithMessage</code>
    <message>WithMessage means there is a message.</message>
    </memo>

    <memo>
    <code>WithoutMessage</code>
    <!-- WithoutMessage so no message -->
    </memo>

    And these documents to be invalid:

    <memo>
    <code>WithoutMessage</code>
    <message>This element shouldn't exist.</message>
    </memo>

    <memo>
    <code>WithMessage</code>
    <!-- There should be a message here -->
    </memo>

    Thanks.

    James McComb
    James McComb, Nov 19, 2003
    #1
    1. Advertising

  2. James McComb

    Bob Foster Guest

    Like this:

    <grammar xmlns="http://relaxng.org/ns/structure/1.0">
    <start>
    <element name="memo">
    <choice>
    <group>
    <element name="code">
    <value>WithMessage</value>
    </element>
    <element name="message">
    <text/>
    </element>
    </group>
    <element name="code">
    <value>WithoutMessage</value>
    </element>
    </choice>
    </element>
    </start>
    </grammar>

    Bob Foster

    "James McComb" <> wrote in message
    news:...
    > Please, can someone tell me how I can express
    > this constraint using Relax NG?
    >
    > I want these documents to be valid:
    >
    > <memo>
    > <code>WithMessage</code>
    > <message>WithMessage means there is a message.</message>
    > </memo>
    >
    > <memo>
    > <code>WithoutMessage</code>
    > <!-- WithoutMessage so no message -->
    > </memo>
    >
    > And these documents to be invalid:
    >
    > <memo>
    > <code>WithoutMessage</code>
    > <message>This element shouldn't exist.</message>
    > </memo>
    >
    > <memo>
    > <code>WithMessage</code>
    > <!-- There should be a message here -->
    > </memo>
    >
    > Thanks.
    >
    > James McComb
    Bob Foster, Nov 20, 2003
    #2
    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. ad
    Replies:
    7
    Views:
    669
    Scott Allen
    Apr 11, 2005
  2. =?Utf-8?B?Q2FybCBNLg==?=
    Replies:
    4
    Views:
    2,479
    sivlookingforu
    Aug 7, 2006
  3. Geert

    RELAX NG text constraint

    Geert, Dec 4, 2004, in forum: XML
    Replies:
    0
    Views:
    409
    Geert
    Dec 4, 2004
  4. brooksr
    Replies:
    3
    Views:
    332
    Jon Paal
    Dec 24, 2006
  5. puvit82
    Replies:
    4
    Views:
    761
    puvit82
    Feb 1, 2008
Loading...

Share This Page