开发者

How to declare empty or not-empty dtd element

开发者 https://www.devze.com 2023-03-28 12:27 出处:网络
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.

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开发者_如何学C 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>
0

精彩评论

暂无评论...
验证码 换一张
取 消