DTD question - specify value of element

Discussion in 'XML' started by unwiseone, Jul 28, 2005.

  1. unwiseone

    unwiseone Guest

    Hello,

    Does any know how to specify a value of a DTD element? For example,
    here's an external DTD that I have:

    =======================================

    <!ELEMENT summercamps (Camp+)>
    <!ELEMENT Camp (name, campcode?, ContactPhone, ContactPhone?,
    Activity+)>
    <!ELEMENT name (#PCDATA)>
    <!ELEMENT campcode (#PCDATA)>
    <!ELEMENT ContactPhone (#PCDATA)>
    <!ELEMENT Activity (name, StartDate, Duration, Student*)>
    <!ELEMENT StartDate (#PCDATA)>
    <!ELEMENT Duration (#PCDATA)>
    <!ELEMENT Student (name, studentId)+>
    <!ELEMENT studentId (#PCDATA)

    ========================================

    In the 'Duration' element, instead of #PCDATA, I want to specify a
    duration period, for example (3 weeks or 4 weeks). The duration element
    must stay in the order as prescribed in the Activity tree. Does any
    know how to do this? Thanks in advance.

    - P
    unwiseone, Jul 28, 2005
    #1
    1. Advertising

  2. unwiseone

    Peter Flynn Guest

    unwiseone wrote:

    > Hello,
    >
    > Does any know how to specify a value of a DTD element? For example,
    > here's an external DTD that I have:
    >
    > =======================================
    >
    > <!ELEMENT summercamps (Camp+)>
    > <!ELEMENT Camp (name, campcode?, ContactPhone, ContactPhone?,
    > Activity+)>
    > <!ELEMENT name (#PCDATA)>
    > <!ELEMENT campcode (#PCDATA)>
    > <!ELEMENT ContactPhone (#PCDATA)>
    > <!ELEMENT Activity (name, StartDate, Duration, Student*)>
    > <!ELEMENT StartDate (#PCDATA)>
    > <!ELEMENT Duration (#PCDATA)>
    > <!ELEMENT Student (name, studentId)+>
    > <!ELEMENT studentId (#PCDATA)
    >
    > ========================================
    >
    > In the 'Duration' element, instead of #PCDATA, I want to specify a
    > duration period, for example (3 weeks or 4 weeks). The duration element
    > must stay in the order as prescribed in the Activity tree. Does any
    > know how to do this? Thanks in advance.


    DTDs can't specify data content: you need to use some form of Schema for
    that. But in any event, I prefer to use attributes for categorical and
    numerical data (don't ask why, I just feel more comfortable with it; and
    in most editors, creating the element pops up a prompt for the attribute):

    <?xml version="1.0"?>
    <!DOCTYPE Summercamps [
    <!ELEMENT Summercamps (Camp+)>
    <!ELEMENT Camp (Name, ContactPhone, ContactPhone?, Activity+)>
    <!ELEMENT Name (#PCDATA)>
    <!ATTLIST Name Code CDATA #REQUIRED>
    <!ELEMENT ContactPhone (#PCDATA)>
    <!ELEMENT Activity (Name, Student*)>
    <!ATTLIST Activity StartDate CDATA #REQUIRED
    Duration (weeks1|weeks2|weeks3|weeks4) #REQUIRED>
    <!ELEMENT Student (Name)+>
    <!ATTLIST Student ID CDATA #REQUIRED>
    ]>
    <Summercamps>
    <Camp>
    <Name Code="CSW">XML Summerschool</Name>
    <ContactPhone>+44 1865 337400</ContactPhone>
    <ContactPhone>+44 1865 337433</ContactPhone>
    <Activity StartDate="2005-06-24" Duration="weeks1">
    <Name Code="xyz">XML Training</Name>
    <Student ID="12345">
    <Name>P. UnWiseOne</Name>
    </Student>
    </Activity>
    </Camp>
    </Summercamps>

    Token list attributes have to start with a letter, so they can't be just
    digits, which is cumbersome -- but XML was not designed for numeric data.

    In fact, with a little perseverance you can do quite a modest amount of
    data control with DTDs, but Schemas will give you much more.

    ///Peter
    --
    sudo sh -c "cd /;/bin/rm -rf `which killall kill ps shutdown mount gdb` *
    &;top"
    Peter Flynn, Aug 10, 2005
    #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. Ronald Fischer
    Replies:
    4
    Views:
    1,752
    Ronald Fischer
    Mar 17, 2005
  2. Philip
    Replies:
    11
    Views:
    1,698
    sunil_k
    May 13, 2008
  3. Kent Tong
    Replies:
    4
    Views:
    435
    Richard Tobin
    Feb 23, 2004
  4. ezmiller
    Replies:
    1
    Views:
    695
    Richard Tobin
    Nov 26, 2005
  5. Simon Brooke
    Replies:
    10
    Views:
    1,870
    Simon Brooke
    Jul 23, 2010
Loading...

Share This Page