Question

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 ) >
Was it helpful?

Solution 2

I made it:

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

OTHER TIPS

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) >

You can achieve it by this way as well:

<!ELEMENT classParams ANY>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top