particular costraints in mixed contents

Discussion in 'XML' started by JU, Jun 27, 2006.

  1. JU

    JU Guest

    Hello,
    I am pretty new in XML and I'm studying the DTD definition. I cannot
    solve a problem, or better, I cannot define what I want in my DTD file.
    What I would like to do is that something like
    <el>text <child/> text</el>
    is accepted but not
    <el>text <child/> text<child/></el>

    I know that <!ELEMENT el (#PCDATA|child)*> declares the element el as a
    mixed content of PCDATA and child but what I want to define is that the
    element child occurs exactly once and not more. Instead of PCDATA can
    occur either before, after or never. I tried with
    (#PCDATA,child+,#PCDATA) but it's not working. Do you know if what I
    want is possible? Thanks a lot in advance, and sorry if it's a silly
    question. bye!
     
    JU, Jun 27, 2006
    #1
    1. Advertising

  2. JU wrote:


    > I know that <!ELEMENT el (#PCDATA|child)*> declares the element el as a
    > mixed content of PCDATA and child but what I want to define is that the
    > element child occurs exactly once and not more. Instead of PCDATA can
    > occur either before, after or never. I tried with
    > (#PCDATA,child+,#PCDATA) but it's not working. Do you know if what I
    > want is possible?


    An XML DTD can't do that. An XML XSD schema however could:

    <xs:element name="el">
    <xs:complexType mixed="true">
    <xs:sequence>
    <xs:element name="child" />
    </xs:sequence>
    </xs:complexType>
    </xs:element>

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jun 27, 2006
    #2
    1. Advertising

  3. JU

    Peter Flynn Guest

    JU wrote:
    > Hello,
    > I am pretty new in XML and I'm studying the DTD definition. I cannot
    > solve a problem, or better, I cannot define what I want in my DTD file.
    > What I would like to do is that something like
    > <el>text <child/> text</el>
    > is accepted but not
    > <el>text <child/> text<child/></el>
    >
    > I know that <!ELEMENT el (#PCDATA|child)*> declares the element el as a
    > mixed content of PCDATA and child but what I want to define is that the
    > element child occurs exactly once and not more. Instead of PCDATA can
    > occur either before, after or never. I tried with
    > (#PCDATA,child+,#PCDATA) but it's not working. Do you know if what I
    > want is possible?


    You can't declare that in XML using a DTD (it would be possible in SGML,
    though, but you don't want to go there). If it's essential to use a DTD,
    you could use subelements of el, for example

    <!ELEMENT el (text,child,text)>
    ....
    <el><text>stuff</text><child/><text>more stuff</text></el>

    or use a W3C Schema instead as Martin suggests.

    ///Peter
     
    Peter Flynn, Jul 3, 2006
    #3
    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. Paras Wadehra
    Replies:
    1
    Views:
    1,789
    =?Utf-8?B?U2F1cmFiaCBOYW5kdQ==?=
    Aug 15, 2004
  2. Don Adams
    Replies:
    1
    Views:
    603
    Martin Honnen
    Mar 5, 2004
  3. Kamarulnizam Rahim
    Replies:
    4
    Views:
    223
    Robert Klemme
    Jan 28, 2011
  4. Zachary
    Replies:
    76
    Views:
    510
    Matt Garrish
    Apr 30, 2006
  5. Replies:
    0
    Views:
    196
Loading...

Share This Page