0

My XML may contain multiple param entries, each with key and value attribute likes this:

<entry id="entry1">
    <classParams>
       <param key="pluginid" value="monitorPlugin" />
       <param key="pluginid2" value="monitorPlugin2" />
    </classParams>
</entry>

AND/OR one single classParams only containing one string like this:

<entry id="entry2">
    <classParams>
      Im a string
    </classParams>
</entry>

My DTD:

<!ELEMENT classParams ( #PCDATA | param* )* >
<!ATTLIST id CDATA #REQUIRED value CDATA #REQUIRED >
<!ELEMENT param ( #PCDATA ) >

How do I define my DTD correctly, concerning the two entry types and the attribute definition for only one type?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Shlomo
  • 3,880
  • 8
  • 50
  • 82

2 Answers2

1

This DTD should work...

<!ELEMENT entry (classParams)>
<!ATTLIST entry
          id CDATA #REQUIRED>

<!ELEMENT classParams (#PCDATA|param)*>

<!ELEMENT param (#PCDATA)>
<!ATTLIST param
          key CDATA #REQUIRED
          value CDATA #REQUIRED>
Daniel Haley
  • 51,389
  • 6
  • 69
  • 95
  • Thanks for the answer. What does `EMPTY` define? What is the definition if I want either `key` OR `id` to be an attribute, not both at the same time allowed but one at least always required? – Shlomo Sep 04 '12 at 15:16
  • `EMPTY` means it's an empty element. In your case, that should be `#PCDATA`. (I'll edit.) In DTD, you can't do "OR" with attribute declarations. The best you could do is make both implied and do the check some other way. – Daniel Haley Sep 04 '12 at 15:51
0

I made it with this definition. I now only use id and put the value in param.

<!ELEMENT classParams ( #PCDATA  | param )* >
         <!ELEMENT param ( #PCDATA ) >
         <!ATTLIST param 
            id CDATA #REQUIRED
         >
Shlomo
  • 3,880
  • 8
  • 50
  • 82