Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to declare empty or not-empty dtd element

Tags:

xml

dtd

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?)>
...
like image 528
Marnix Avatar asked Jan 18 '26 04:01

Marnix


1 Answers

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>
like image 69
Daniel Haley Avatar answered Jan 19 '26 18:01

Daniel Haley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!