在DTD中重用元素

问题描述

| 我已经开始工作,并得到一些XML文件和DTD。它们工作正常,但我在DTD中注意到它们正在重用这样的元素。 DTD:
<!ELEMENT image EMPTY>
    <!ATTLIST image 
        source CDATA #required
        signature (true|false|1|0) \"false\" 
    >
并且在xml中,image元素出现在两个位置,但是只有一个位置需要\'signature \'属性,在另一情况下则不相关。 XML:
<root>
  <element-with-optional-signature-image>
     <image source=\"1.jpg\" singature=\"true\" />
     <image source=\"2.jpg\" />
  </element-with-optional-signature-image>
  <other>
     <image source=\"3.jpg\" />
  </other>
</root>
我以前从未见过像这样编写的DTD,只是想知道这样做是普遍的还是非常糟糕的方式?我会创建两个不同的元素
element-image
other-image
。 编辑- 以上是否像这样的DTD一样被接受:
<!ELEMENT element-image EMPTY>
    <!ATTLIST element-image 
        source CDATA #required
        signature (true|false|1|0) \"false\" 
    >

<!ELEMENT other-image EMPTY>
    <!ATTLIST image 
        source CDATA #required
    >
使用这样的XML:
<root>
  <element-with-optional-signature-image>
     <element-image source=\"1.jpg\" singature=\"true\" />
     <element-image source=\"2.jpg\" />
  </element-with-optional-signature-image>
  <other>
     <other-image source=\"3.jpg\" />
  </other>
</root>
    

解决方法

我认为重用这样的元素是个好主意。它使XML保持简单和冗长。 在这种情况下,我认为仅仅因为不需要使用可选属性就可以创建一个新元素。     ,在此DTD中,不需要签名属性。源属性是。