How can I declare an element in DTD that is self-closing or contains elements? I have found the *-operator, but I can't verify if this can also validate empty elements.
I have tried this, but it gives a compilation error in Visual Studio saying that the EMPTY element is not declared:
<!ELEMENT File (Annotations|EMPTY)>
<!ELEMENT Annotations (State*)>
<!ELEMENT State EMPTY>
Or I could try the following, but I can't validate if it is ok:
<!ELEMENT File (Annotations?)>
...
Yes, your element declaration for File is correct:
<!ELEMENT File (Annotations?)>
What you're saying is that File can contain zero or one Annotations element.
Also, if you would've used * instead of ?, you would've been saying File can contain zero or more Annotations elements.
Valid examples:
<!DOCTYPE File [
<!ELEMENT File (Annotations?)>
<!ELEMENT Annotations (State*)>
<!ELEMENT State EMPTY>
]>
<File/>
<!DOCTYPE File [
<!ELEMENT File (Annotations?)>
<!ELEMENT Annotations (State*)>
<!ELEMENT State EMPTY>
]>
<File></File>
<!DOCTYPE File [
<!ELEMENT File (Annotations?)>
<!ELEMENT Annotations (State*)>
<!ELEMENT State EMPTY>
]>
<File>
<Annotations/>
</File>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With