Reputation: 3990
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 ) >
Upvotes: 2
Views: 1387
Reputation: 25054
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) >
Upvotes: 2
Reputation: 3990
I made it:
<!ELEMENT classParams ( #PCDATA | pluginid | bla | tag )* >
Upvotes: 2