开发者

How to declare empty or not-empty dtd element

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜