Re: DTD Nested mixed content in XSD

Discussion in 'XML' started by Bob Foster, Jul 26, 2003.

  1. Bob Foster

    Bob Foster Guest

    "Theo" <> wrote in message
    news:...
    > How do I create the following in XSD:
    >
    > <!ELEMENT whatever (node1, (#PCDATA | node2 | node3)*)


    This is not valid XML. The mixed syntax is only allowed at the top level.

    > Here "node1" MUST be the first child in "whatever" node and then
    > either text or "node2" or "node3" can come after. Thanks in advance!


    AFAIK, you can't express this with XML Schema, either. You can't mix mixed
    (no pun intended) and non-mixed types in derivation by extension, and model
    groups don't allow you to specify mixed.

    As usual, RELAX NG has no such restriction.

    <element name="whatever">
    <element name="node1"/>
    <zeroOrMore>
    <mixed>
    <choice>
    <element name="node2"/>
    <element name="node3"/>
    </choice>
    </mixed>
    </zeroOrMore>
    </element>

    Defines the model you're trying for. (But I can hear you saying, "Huh?" ;-)

    Bob Foster

    [Disclaimer: I just typed that stuff in. If it doesn't compile, validate or
    fly to the moon, write your congressman.]
    Bob Foster, Jul 26, 2003
    #1
    1. Advertising

  2. Bob Foster

    Theo Guest

    Thanks for the reply Bob.

    Are you sure this is not valid XML? What's interesting is that the
    specified DTD works in Epic Editor, but not in XML Spy. And why does
    RELAX NG let you define this if it is not valid?

    Do you think XML Schema does not allow mixed content in model groups
    because it is not valid XML? Or is this just a limitation of XML
    Schema?



    "Bob Foster" <> wrote in message news:<qnBUa.154039$Ph3.18349@sccrnsc04>...
    > "Theo" <> wrote in message
    > news:...
    > > How do I create the following in XSD:
    > >
    > > <!ELEMENT whatever (node1, (#PCDATA | node2 | node3)*)

    >
    > This is not valid XML. The mixed syntax is only allowed at the top level.
    >
    > > Here "node1" MUST be the first child in "whatever" node and then
    > > either text or "node2" or "node3" can come after. Thanks in advance!

    >
    > AFAIK, you can't express this with XML Schema, either. You can't mix mixed
    > (no pun intended) and non-mixed types in derivation by extension, and model
    > groups don't allow you to specify mixed.
    >
    > As usual, RELAX NG has no such restriction.
    >
    > <element name="whatever">
    > <element name="node1"/>
    > <zeroOrMore>
    > <mixed>
    > <choice>
    > <element name="node2"/>
    > <element name="node3"/>
    > </choice>
    > </mixed>
    > </zeroOrMore>
    > </element>
    >
    > Defines the model you're trying for. (But I can hear you saying, "Huh?" ;-)
    >
    > Bob Foster
    >
    > [Disclaimer: I just typed that stuff in. If it doesn't compile, validate or
    > fly to the moon, write your congressman.]
    Theo, Jul 28, 2003
    #2
    1. Advertising

  3. In article <>,
    Theo <> wrote:

    >Are you sure this is not valid XML? What's interesting is that the
    >specified DTD works in Epic Editor, but not in XML Spy. And why does
    >RELAX NG let you define this if it is not valid?


    It's not really a question of "valid". The declaration

    >> > <!ELEMENT whatever (node1, (#PCDATA | node2 | node3)*)


    is just not well formed. Any XML parser should reject it (assuming
    that the declaration is in a part of the DTD that it reads). And
    there's no way to express the intended content in a DTD.

    The same is true with XML Schema. It Does allow more forms than DTDs
    - you can have an arbitrary element content model interspersed with
    text - but it don't allow this one. There's nothing about XML that
    forced XML Schema not to support this, it just doesn't happen to.

    Relax NG *does* let you specify this sort of content.

    >Do you think XML Schema does not allow mixed content in model groups
    >because it is not valid XML? Or is this just a limitation of XML
    >Schema?


    So yes, it's just a limitation of XML Schemas.

    -- Richard
    --
    Spam filter: to mail me from a .com/.net site, put my surname in the headers.

    FreeBSD rules!
    Richard Tobin, Jul 28, 2003
    #3
  4. Bob Foster

    Bob Foster Guest

    I stand corrected. The DTD fragment is valid but not well-formed. ;-}

    Theo, the question "why does RELAX NG let you define this if it is not
    valid" reveals a deeper misunderstanding.

    XML lets you write anything that is well-formed. What you want to do is
    perfectly ok for an instance document.

    But the various schema languages for XML (DTD, W3 XML Schema, RELAX NG,
    Schematron, etc.) can't describe every document format that you can possibly
    come up with. In general, each schema language allows you to describe a
    different subset of all possible formats.

    Just because a schema language can't describe a document format doesn't mean
    you can't use the format, it just means that you can't use a validator based
    on that schema language to verify that an instance document conforms to the
    schema. Lots of people use XML with no DTDs or schemas and get along just
    fine; the applications that read the XML do all the validating they need.
    Others choose the schema language that best suits what they are trying to
    do.

    However, sometimes you are forced to use one or the other schema languages.
    Then you have to settle for whatever approximation of your desired format
    the language will support.

    Is that more clear?

    Bob


    "Richard Tobin" <> wrote in message
    news:bg373m$ksu$...
    > In article <>,
    > Theo <> wrote:
    >
    > >Are you sure this is not valid XML? What's interesting is that the
    > >specified DTD works in Epic Editor, but not in XML Spy. And why does
    > >RELAX NG let you define this if it is not valid?

    >
    > It's not really a question of "valid". The declaration
    >
    > >> > <!ELEMENT whatever (node1, (#PCDATA | node2 | node3)*)

    >
    > is just not well formed. Any XML parser should reject it (assuming
    > that the declaration is in a part of the DTD that it reads). And
    > there's no way to express the intended content in a DTD.
    >
    > The same is true with XML Schema. It Does allow more forms than DTDs
    > - you can have an arbitrary element content model interspersed with
    > text - but it don't allow this one. There's nothing about XML that
    > forced XML Schema not to support this, it just doesn't happen to.
    >
    > Relax NG *does* let you specify this sort of content.
    >
    > >Do you think XML Schema does not allow mixed content in model groups
    > >because it is not valid XML? Or is this just a limitation of XML
    > >Schema?

    >
    > So yes, it's just a limitation of XML Schemas.
    >
    > -- Richard
    > --
    > Spam filter: to mail me from a .com/.net site, put my surname in the

    headers.
    >
    > FreeBSD rules!
    Bob Foster, Jul 30, 2003
    #4
  5. Bob Foster

    Theo Guest

    Yes I understand now. It is clear that XSD can't do everything we had
    in the DTD, but it is close enough for us to still be able to use.
    Thank you everyone for all your help!
    Theo, Jul 30, 2003
    #5
  6. Bob Foster

    Bob Foster Guest

    "Theo" <> wrote in message
    news:...
    > Yes I understand now. It is clear that XSD can't do everything we had
    > in the DTD, but it is close enough for us to still be able to use.
    > Thank you everyone for all your help!


    Just out of curiosity, if you're still reading this thread, what parser were
    you using this (not well-formed) DTD with?

    Bob Foster
    Bob Foster, Jul 31, 2003
    #6
  7. Bob Foster

    Theo Guest

    In our application the DTD was originally used with Epic Editor to
    create XML files. However, we are now trying to convert the DTD into
    XSD using XMLSpy. XMLSpy, interestingly enough, does not accept the
    not well-formed DTD. So it seems Epic Editor is less strict with its
    validation and allowed us to get away with it.

    -theo


    "Bob Foster" <> wrote in message news:<g7_Va.23858$YN5.22097@sccrnsc01>...
    > "Theo" <> wrote in message
    > news:...
    > > Yes I understand now. It is clear that XSD can't do everything we had
    > > in the DTD, but it is close enough for us to still be able to use.
    > > Thank you everyone for all your help!

    >
    > Just out of curiosity, if you're still reading this thread, what parser were
    > you using this (not well-formed) DTD with?
    >
    > Bob Foster
    Theo, Aug 4, 2003
    #7
  8. Bob Foster

    Bob Foster Guest

    "Theo" <> wrote in message
    news:...
    > In our application the DTD was originally used with Epic Editor to
    > create XML files. However, we are now trying to convert the DTD into
    > XSD using XMLSpy. XMLSpy, interestingly enough, does not accept the
    > not well-formed DTD. So it seems Epic Editor is less strict with its
    > validation and allowed us to get away with it.


    Yes, you will have to fix the DTD. When you do, you might like to try James
    Clark's trang program, which does a bang-up job of converting DTD to XSD.
    Just google on trang.

    Bob Foster
    Bob Foster, Aug 6, 2003
    #8
    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. Joseph Tilian
    Replies:
    0
    Views:
    339
    Joseph Tilian
    Dec 21, 2004
  2. Ronald Fischer
    Replies:
    4
    Views:
    1,743
    Ronald Fischer
    Mar 17, 2005
  3. Fender Mussel
    Replies:
    0
    Views:
    544
    Fender Mussel
    Sep 14, 2004
  4. Matt
    Replies:
    3
    Views:
    37,203
    MKNDK
    Sep 11, 2008
  5. test
    Replies:
    2
    Views:
    1,995
    Oliver Wong
    Jul 28, 2006
Loading...

Share This Page