2011-08-17 32 views
3

如何声明DTD中自闭或包含元素的元素?我找到了*-operator,但我无法验证这是否也可以验证空元素。如何声明空或非空dtd元素

我已经试过这一点,但它提供了在Visual Studio中说,EMPTY元素不声明编译错误:

<!ELEMENT File (Annotations|EMPTY)> 
<!ELEMENT Annotations (State*)> 
<!ELEMENT State EMPTY> 

或者我可以尝试以下方法,但如果是我无法验证OK:

<!ELEMENT File (Annotations?)> 
... 

回答

1

是,为File你的元素声明是正确的:

<!ELEMENT File (Annotations?)> 

你在说什么,File可以包含零个或一个Annotations元素。

另外,如果你已经使用*代替?,你会一直在说File可以包含零个或更多Annotations元素。

有效例子:

<!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

所以含零个元素是相同的声明的话说:这个元素将在同一行的结束斜线?这实际上是我的问题...... – Marnix 2011-08-17 22:27:33