Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > DTD question - specify value of element

Reply
Thread Tools

DTD question - specify value of element

 
 
unwiseone
Guest
Posts: n/a
 
      07-28-2005
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

 
Reply With Quote
 
 
 
 
Peter Flynn
Guest
Posts: n/a
 
      08-10-2005
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"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
In a DTD, how do I specify that an element contains arbitrary othermarkup? Simon Brooke XML 10 07-23-2010 08:35 AM
table hastle when I specify DocType (DTD) Philip HTML 11 05-13-2008 01:41 PM
xml schema to specify element type based on attribute value? James XML 2 07-28-2007 04:11 AM
How to specify DTD to DTD.getDTD for DocumentParser? Ronald Fischer Java 4 03-17-2005 09:37 AM
specify html target value based on xml element Richard G. XML 1 06-27-2004 11:35 AM



Advertisments