Frequently used DTD/XML schema expressions ?

Discussion in 'XML' started by Razvan, Feb 7, 2005.

  1. Razvan

    Razvan Guest

    Hi !




    Where can I find the definition of the most used DTD/Schema
    expressions ? Something like:


    <!-- exclusive or: AAA or BBB but not both -->
    <!ELEMENT TestXOR (AAA | BBB)>

    <!-- or: AAA or BBB (could be one, both (any order) or none) -->
    <!ELEMENT TestOR1 (AAA | BBB | (AAA, BBB) | (BBB, AAA))?>
    <!ELEMENT TestOR2 ((AAA?, BBB?) | (BBB, AAA))>

    <!-- and: AAA and BBB (in this order) -->
    <!ELEMENT TestAND1 (AAA, BBB)>

    <!-- and: AAA and BBB (in this order) or none -->
    <!ELEMENT TestAND2 (AAA, BBB)?>



    Thanks,
    Razvan
     
    Razvan, Feb 7, 2005
    #1
    1. Advertising

  2. /Razvan/:

    > Where can I find the definition of the most used DTD/Schema
    > expressions ? Something like:
    >
    > <!-- exclusive or: AAA or BBB but not both -->
    > <!ELEMENT TestXOR (AAA | BBB)>

    [...]

    You find it in the XML specification <http://www.w3.org/TR/REC-xml/>.

    "Element Type Declarations" <http://www.w3.org/TR/REC-xml/#elemdecls>

    --
    Stanimir
     
    Stanimir Stamenkov, Feb 7, 2005
    #2
    1. Advertising

  3. Razvan

    Razvan Guest

    Hi



    You did not understand me. I am looking for a web page where
    I can find all sort of expression written according to DTD rules or XML
    Schema rules, like:


    (a or b or c) xor d
    (a and b) or c
    (a or b) xor c

    a.s.o

    In the official docs I can only find a few random examples.
    Practically I am searching for a DTD/XML schema repository. I
    hope that I am more clear this time.



    Regards,
    Razvan
     
    Razvan, Feb 8, 2005
    #3
  4. /Razvan/:

    > You did not understand me. I am looking for a web page where
    > I can find all sort of expression written according to DTD rules or XML
    > Schema rules, like:

    [...]
    > In the official docs I can only find a few random examples.


    The official document specifies all the possibilities, but seems
    you're too lazy to read. How a specification could not specify
    something - it won't be specified and it won't be recognized, then.
    Just follow the links in the BNF notations:

    > Element Type Declaration
    >
    > [45] elementdecl ::= '<!ELEMENT' S Name S contentspec S? '>'
    > [46] contentspec ::= 'EMPTY' | 'ANY' | Mixed | children
    >
    > Element-content Models
    >
    > [47] children ::= (choice | seq) ('?' | '*' | '+')?
    > [48] cp ::= (Name | choice | seq) ('?' | '*' | '+')?
    > [49] choice ::= '(' S? cp ( S? '|' S? cp )+ S? ')'
    > [50] seq ::= '(' S? cp ( S? ',' S? cp )* S? ')'


    etc., etc. Here are some more:

    "Attribute-List Declarations" <http://www.w3.org/TR/REC-xml/#attdecls>

    Read the whole document. For the XML Schema language:

    http://www.w3.org/XML/Schema#dev


    /Razvan/:

    > Practically I am searching for a DTD/XML schema repository. I
    > hope that I am more clear this time.


    Can't help you here.

    --
    Stanimir
     
    Stanimir Stamenkov, Feb 8, 2005
    #4
  5. Razvan

    Razvan Guest

    You are too laizy to read. I have already read the damn document before
    you pinpointed it to me. I am looking for best practices for a lot of
    expresions that must be very frequently used, like:

    <!-- or: AAA or BBB (could be one, both (any order) or none) -->
    <!ELEMENT TestOR1 (AAA | BBB | (AAA, BBB) | (BBB, AAA))?>
    <!ELEMENT TestOR2 ((AAA?, BBB?) | (BBB, AAA))>

    As you can see there are 2 ways to do the same thing.

    The best way to write DTDs from scratch is to have a set of "bricks" to
    help you build it faster and in a proper way. It is a waste of time to
    think each time how to implement the above relation => it is useful to
    write a list of frequently-used expressions.

    About the "lazy" stuff: use a civilized language. I don't take crap
    from you or anybody else.



    Razvan
     
    Razvan, Feb 8, 2005
    #5
  6. In article <>,
    Razvan <> wrote:
    > You did not understand me. I am looking for a web page where
    >I can find all sort of expression written according to DTD rules or XML
    >Schema rules, like:


    I don't think you're likely to find this, because it's supposed to be
    obvious. I'm sure are there are FAQs with examples of some well known
    tricky cases, such as N elements in any order.

    -- Richard
     
    Richard Tobin, Feb 8, 2005
    #6
  7. Razvan

    Razvan Guest

    Hi


    Can you pinpoint me to such FAQ ? Yesterday I spent half a day
    trying to find something like this but I gave up. The amount of
    information is tremendous. I probably need to spend one full week just
    to parse the most important sites.



    Thanks,
    Razvan
     
    Razvan, Feb 8, 2005
    #7
  8. /Razvan/:

    > You are too laizy to read. I have already read the damn document before
    > you pinpointed it to me. I am looking for best practices for a lot of
    > expresions that must be very frequently used, like:


    Hm. May be I haven't understood you completely, still I think
    you're... whatever you are. :)

    > <!-- or: AAA or BBB (could be one, both (any order) or none) -->
    > <!ELEMENT TestOR1 (AAA | BBB | (AAA, BBB) | (BBB, AAA))?>
    > <!ELEMENT TestOR2 ((AAA?, BBB?) | (BBB, AAA))>
    >
    > As you can see there are 2 ways to do the same thing.


    In the XML specification there's a section "Deterministic Content
    Models" <http://www.w3.org/TR/REC-xml/#determinism> which might be
    of interest to you.

    > The best way to write DTDs from scratch is to have a set of "bricks" to
    > help you build it faster and in a proper way. It is a waste of time to
    > think each time how to implement the above relation => it is useful to
    > write a list of frequently-used expressions.


    I write a DTD according to what an XML structure must look like. As
    to best practices in representing data as XML, I can't give you
    concrete resources, but I'm sure there are many articles regarding
    different situations - "Elements vs. attributes", etc.

    > About the "lazy" stuff: use a civilized language. I don't take crap
    > from you or anybody else.


    I don't take crap from you, too. Use more suitable explanation next
    time... "web page where I can find all sort of expression written
    according to DTD rules..." - that's what you get from the spec.

    --
    Stanimir
     
    Stanimir Stamenkov, Feb 8, 2005
    #8
  9. Razvan

    Razvan Guest

    Hi


    Since you mention it: how do you write N elements in any order
    ? These are my solutions for 2 elements: (DTD)

    <!ELEMENT TestOR1 (AAA | BBB | (AAA, BBB) | (BBB, AAA))?>
    <!ELEMENT TestOR2 ((AAA?, BBB?) | (BBB, AAA))>




    Thanks,
    Razvan
     
    Razvan, Feb 8, 2005
    #9

  10. > Since you mention it: how do you write N elements in any order
    > ? These are my solutions for 2 elements: (DTD)
    >
    > <!ELEMENT TestOR1 (AAA | BBB | (AAA, BBB) | (BBB, AAA))?>
    > <!ELEMENT TestOR2 ((AAA?, BBB?) | (BBB, AAA))>
    >


    TestOR1 isn't allowed in XML as it fails this test:
    http://www.w3.org/TR/xml11/#determinism

    When you come to an AAA element

    <!ELEMENT TestOR1 (AAA | BBB | (AAA, BBB) | (BBB, AAA))?>
    ^^^^ ^^^

    you can't tell which of the two indicated AAA you have without looking
    ahead to see if there is a BBB and such lookahead isn't allowed.

    Similarly your TestOR2 fails as it's OK for AAA but given a BBB
    you can't tell whether it matches (AAA?, BBB?) or (BBB, AAA)

    I think to allow any of
    empty
    AAA
    BBB
    AAA,BBB
    BBB,AAA

    you need something like:

    (AAA,BBB?)|(BBB,AAA?)?

    David
     
    David Carlisle, Feb 8, 2005
    #10
  11. Razvan

    Razvan Guest

    That means XML SPY is broken ? It allowed without any problems the
    above expressions (*both* of them). What if your DTD contain some
    undeterministic expressions - like the above mentioned ones. What are
    the risks ? Some validating parsers will accept them while others might
    not ?



    Regards,
    Razvan
     
    Razvan, Feb 8, 2005
    #11
  12. checking for non determinism is classified as "an error" that means that
    http://www.w3.org/TR/xml11/#dt-error
    Conforming software MAY detect and report an error and MAY recover from it.]

    so it means strictly speaking XML Spy is conforming not to report this
    error, but your file is still in error.


    I see Richard has already commented on this thread, personally I always
    check things with his excellent rxp parser which says given:

    <!DOCTYPE TestOR1 [
    <!ELEMENT TestOR1 (AAA | BBB | (AAA, BBB) | (BBB, AAA))?>
    <!ELEMENT TestOR2 ((AAA?, BBB?) | (BBB, AAA))>
    ]>
    <TestOR1/>



    $ rxp -sxV d.xml
    Warning: Content model for TestOR1 is not deterministic.
    At start of content there are multiple choices when the next element is AAA.
    (detected at end of prolog of document file:///e:/tmp/d.xml)
    Warning: Content model for TestOR2 is not deterministic.
    At start of content there are multiple choices when the next element is BBB.
    (detected at end of prolog of document file:///e:/tmp/d.xml)


    Note this error is only optionally reported when using a dtd. The
    equivalent thing in W3C schema is called the unique particle constraint
    http://www.w3.org/TR/xmlschema-1/#cos-nonambig
    and as far as I can see, a conforming schema validator has to report
    this.

    One way to avoid all this nonsense is to use a different schema language
    such as Relax NG.

    David
     
    David Carlisle, Feb 8, 2005
    #12
  13. Razvan

    Razvan Guest

    Thanks a lot for the tip with the rxp parser. I just install it. I
    really needed a parser to check for valid DTDs / XML Schemas. I am new
    to this XML stuff and without your mention I would have started on the
    wrong path.


    >One way to avoid all this nonsense is to use a different schema

    language
    >such as Relax NG.


    This is not possible. I am preparing to take IBM 141 certification
    exam - "XML and related technologies". For the moment I will
    concentrate on the exam's objectives. For whatever reason Relax NG is
    not on their objective list. Later, I might look at alternative
    technologies.



    Regards,
    Razvan
     
    Razvan, Feb 8, 2005
    #13
    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.

Share This Page