2

My .xml structure may have the following data:

<entry id="one-string">
            <class>nmWinMultiReports_main</class>
            <classParams>string</classParams>
         </entry>
<entry id="multiple-elements">
            <class>nmJavaScript_main</class>
            <classParams>
               <pluginid>monitorPlugin</pluginid>
               <bla>string</bla>
               <tag>abc</tag>
            </classParams>
         </entry>

How do I define the .dtd file to allow classParams to either 1. be a string or 2. multiple sub elements (each once)?

I tried:

<!ELEMENT class ( #PCDATA ) >
<!ELEMENT classParams ( #PCDATA | pluginid | bla | tag ) >
         <!ELEMENT pluginid ( #PCDATA ) >
         <!ELEMENT bla ( #PCDATA ) >
         <!ELEMENT tag ( #PCDATA ) >
Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Shlomo
  • 3,880
  • 8
  • 50
  • 82

3 Answers3

2

DTDs cannot enforce the constraint you describe; the easiest way to get something like that constraint is to add a new element (call it string) and declare classParams as taking either string or the sequence of pluginid etc. as children:

<!ELEMENT string (#PCDATA) >
<!ELEMENT classParams (string 
                      | (pluginid, bla, tag))
>

Alternatively, if

<classParams><string>foo</string></classParams> 

seems too heavy, you could declare entry as taking either classParams or classParamString as content:

<!ELEMENT entry (class, (classParams | classParamString)) >
<!ELEMENT classParamString (#PCDATA) >
<!ELEMENT classParams (pluginid, bla, tag) >
C. M. Sperberg-McQueen
  • 24,596
  • 5
  • 38
  • 65
  • Thank you for your answer. I am currently using my construct but will possibly use your approach in the future. – Shlomo Sep 10 '12 at 10:26
1

I made it:

<!ELEMENT classParams ( #PCDATA | pluginid | bla | tag )* >
Shlomo
  • 3,880
  • 8
  • 50
  • 82
  • Useful. Any idea why this one works and the other doesn't? Is it actually doing what it looks like it's doing? – Joel Cross Oct 22 '13 at 13:59
0

You can achieve it by this way as well:

<!ELEMENT classParams ANY>