Relax NG specification oddity

Discussion in 'XML' started by withtape@gmail.com, May 17, 2006.

  1. Guest

    Somebody please, please help me. I'm getting started using Relax NG to
    describe document schemas. After reading the grammar summarized by
    http://www.relaxng.org/spec-20011203.html (Section 5), I conclude that
    the following is a valid Relax NG schema:

    <grammar xmlns="http://relaxng.org/ns/structure/1.0">
    <start>
    <attribute name="wtf"/>
    </start>
    </grammar>

    That is, the grammar defines no document element, and that document
    element must have a "wtf" attribute.

    Elsewhere in the specification (Appendix A) is a Relax NG schema for
    Relax NG schemas, and validating the above XML against the schema for
    Relax NG (using Tenuto) indeed declares it a valid Relax NG schema.
    Yet, there is no possible XML document that could validate against it!

    This doesn't present any problem when validating the eventual documents
    that must match the "WTF" schema: no document will ever validate
    against it. But (as I understand) it means that anyone writing Relax NG
    schemas must take care above and beyond what is demanded by the Relax
    NG specification to avoid creating such a "WTF" schema. Otherwise, he
    confronts a paradox of having a schema vouch-safed (by the Relax NG
    spec) as suitable for validating XML documents, that cannot possibly
    validate any XML document.

    Why do I care? Well, I am writing a tool that assists in the creation
    of valid XML documents by "suggesting" appropriate elements and values
    at various points in a document according to a given schema. Included
    within will be a tool to assist creating schemas, based on the Relax NG
    meta-schema. Am I to understand that, if I desire to avoid allowing the
    creation of "impossible" schemas like above, it will be insufficient to
    simply implement the Relax NG meta-schema? Must I include additional,
    Relax NG-specific fixes to check for such things (I wish to avoid this
    because it would not be standard)?

    More generally, is this a flaw in Relax NG? Does it make sense for a
    schema-definition language to allow schemas that cannot validate any
    possible document? Was Relax NG deliberately designed this way, or is
    this an oversight? Do other schema-definition languages allow this
    situation?
    , May 17, 2006
    #1
    1. Advertising

  2. wrote:
    > More generally, is this a flaw in Relax NG?


    I don't know enough about RELAX NG to answer this, but I would suggest
    contacting the folks responsible for its design and posing this question
    directly to them. They're the ones who can say for sure whether it's
    design or accident, and whether it will be declared acceptable or an
    erratum.

    http://www.relaxng.org/ points to a mailing list for RELAX NG, as well
    as a long list of documents and tools. (I presume you've already looked
    at that list, both to make sure your tool isn't redundant and to see
    what they do when presented with this schema...)

    Good luck. Let us know what you find out.

    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
    Joe Kesselman, May 17, 2006
    #2
    1. Advertising

  3. Guest

    Thanks for the pointer! Actually, I had missed that in the sea of links
    on that page. I would say that's exactly what I'm looking for, so I'll
    check that out and followup if I get new info.
    , May 17, 2006
    #3
  4. George Bina Guest

    Hi,

    The Relax NG grammar for Relax NG does not check all the rules for
    having a valid grammar. This applies also for XML Schema where if a
    document is valid against the schema for schemas that does not mean it
    is a valid XML Schema.

    The grammar from our example is not valid, Jing reports an error
    because the start element contains attribute.
    See this also in the specification:
    http://www.relaxng.org/spec-20011203.html#context-start
    ***
    7.1.5. start element
    The following paths are prohibited:

    * start//attribute
    [...]
    ***

    A sample schema that will check only that the root element contains a
    wtf attribute is:

    <?xml version="1.0" encoding="UTF-8"?>
    <grammar xmlns="http://relaxng.org/ns/structure/1.0" ns="">
    <start>
    <element>
    <anyName/>
    <attribute name="wtf"/>
    <zeroOrMore>
    <choice>
    <attribute>
    <anyName>
    <except>
    <name>wtf</name>
    </except>
    </anyName>
    </attribute>
    <text/>
    <ref name="any"/>
    </choice>
    </zeroOrMore>
    </element>
    </start>
    <define name="any">
    <element>
    <anyName/>
    <zeroOrMore>
    <choice>
    <attribute>
    <anyName/>
    </attribute>
    <text/>
    <ref name="any"/>
    </choice>
    </zeroOrMore>
    </element>
    </define>
    </grammar>

    or in compact syntax

    start =
    element * {
    attribute wtf { text },
    (attribute * - wtf { text }
    | text
    | any)*
    }
    any =
    element * {
    (attribute * { text }
    | text
    | any)*
    }

    Best Regards,
    George
    ---------------------------------------------------------------------
    George Cristian Bina
    <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
    http://www.oxygenxml.com
    George Bina, May 17, 2006
    #4
  5. Guest

    George,
    Thanks so much for your help! I confess to being overwhelmed by the
    specification, so I did not consider those separate prohibitions.

    To be clear, your example demonstrating how to ensure that, whatever
    the root element of a document is, it must have a "wtf" attribute, is
    good reference, but not applicable to my situation. I contrived the
    example of a "headless" attribute to point out what I took to be the
    deficiency of the grammar, but I thank you for the demonstration.

    The main point I wanted to address is whether it is possible to devise
    a Relax NG schema that, in itself, ensures valid schemas. I see now
    that the grammar given in the spec, expressed as a schema, fails at
    this task, for good reasons (for example, I came across a post on the
    Relax NG mailing list that, I believe, explains how partial schemas
    like my example could be referenced by other schemas, and thus the
    grammar allows them). I wonder if that schema/grammar could be refined
    so that a schema-producing program would have no external requirements
    (such as, "start//attribute is invalid"). Perhaps by adding
    restrictions on allowed elements after <start>, at the expense of
    allowing external schema references (a trade I would be willing to make
    for my purposes)?

    Really, I just wanted reassurance that I wasn't crazy in thinking that
    the Relax NG schema for Relax NG schemas does something other than what
    I initially expected, and you have provided it very nicely.

    -Jason Chang
    , Jun 12, 2006
    #5
    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. Jari Kujansuu
    Replies:
    0
    Views:
    813
    Jari Kujansuu
    Sep 4, 2003
  2. James McComb
    Replies:
    1
    Views:
    371
    Bob Foster
    Nov 20, 2003
  3. Pieter
    Replies:
    6
    Views:
    425
    Pieter
    Nov 28, 2003
  4. Morten W. Petersen
    Replies:
    0
    Views:
    443
    Morten W. Petersen
    Feb 2, 2004
  5. Geert

    RELAX NG text constraint

    Geert, Dec 4, 2004, in forum: XML
    Replies:
    0
    Views:
    409
    Geert
    Dec 4, 2004
Loading...

Share This Page