repeating ELEMENTs in DTD

Status
Not open for further replies.

Billy Ng

Usenet Archive
Joined
Aug 21, 2001
Messages
10
Reaction score
0
Hi folks,

Let's say I have this xml

<commands>
<classess>
<option value="1">A.</option>
<option value="2">B</option>
<option value="3">C</option>
</classess>
<areas>
<option county="..." value="1">A.</option>
<option county="..." value="2">B</option>
<option county="..." value="3">C</option>
</areas>
</commands>

The classes and areas tags both contains option tags. All option tag contains value attributes. When I make the DTD, I need to define the option ELEMENTs for both classess and areas tags. Will this confuse the xml parser? Is it legal?

<!ELEMENT commands (classes, areas)>
<!ELEMENT classes (option)>
<!ELEMENT option (#PCDATA)>
<!ATTLIST option value CDATA #REQUIRED>
<!ELEMENT areas (county, option)>
<!ELEMENT county (#PCDATA)>
<!ELEMENT option (#PCDATA)>
<!ATTLIST option value CDATA #REQUIRED>

Thanks in advance!

Billy Ng
 

Peter Flynn

Usenet Archive
Joined
Jan 2, 2000
Messages
1,813
Reaction score
0
Billy Ng wrote:
Hi folks,

Let's say I have this xml

<commands>
<classess>
<option value="1">A.</option>
<option value="2">B</option>
<option value="3">C</option>
</classess>
<areas>
<option county="..." value="1">A.</option>
...

No.

Is it legal?

Yes, perfectly. It's exactly what the technology was designed for.

<!ELEMENT commands (classes, areas)>
<!ELEMENT classes (option)>

Except this should be <!ELEMENT classes (option+)> because you can have more than one option.

<!ELEMENT option (#PCDATA)>
<!ATTLIST option value CDATA #REQUIRED>
<!ELEMENT areas (county, option)>

This is wrong, county is not an element type, it's an attribute on option. You need to say:

<!ELEMENT option (#PCDATA)>
<!ATTLIST option value CDATA #REQUIRED county CDATA #IMPLIED> <!ELEMENT areas (option+)>

so that areas has exactly the same content model as classes. But attributes are either compulsory or they're not, always. You can't have county #REQUIRED when option occurs inside areas but absent if it occurs inside classes. You must be consistent. If you need to represent that data differently, don't call it an option. Call it something else and give it its own set of attributes.

<!ELEMENT county (#PCDATA)>
<!ELEMENT option (#PCDATA)>
<!ATTLIST option value CDATA #REQUIRED>

No, no, no. You can only declare an element type once. County is wrong anyway, it's an attribute (see above). And you've already declared option, so you can't declare it again.

///Peter
 
Status
Not open for further replies.

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,049
Messages
3,104,246
Members
248,133
Latest member
DujonT

Latest Threads

Top