如何声明多个元素共有的属性? [英] How do I declare attributes common to multiple elements?

查看:89
本文介绍了如何声明多个元素共有的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个元素要赋予这些属性:

I have multiple elements I want to give these attributes:

<!ATTLIST [all these elements]
    width   CDATA   "0"
    height  CDATA   "0"
    margin  CDATA   "0 0 0 0"
    padding CDATA   "0 0 0 0"
    rotation CDATA  "0"
    halign  (left|center|right|full)    "center"
    valign  (top|middle|bottom|full)    "middle"
    >

在DTD中这是否有可能,还是我必须手动进行?

Is this possible somehow in DTD, or will I have to do it manually?

(而且,当我在这里时,我认为声明 margin padding 这样的属性。有人知道更好的方法吗?)

(Also, while I'm here, I don't think it was such a good idea to declare the margin and padding attributes that way. Does anyone know a better way?)

推荐答案

每个元素需要有自己的属性声明 ATTLIST )。但是,您可以使用参数实体重用它的大部分。

Each element needs to have its own attribute declaration (ATTLIST). However, you can use a parameter entity to reuse the bulk of it.

示例...

<!ENTITY % attrs 
    'width   CDATA   "0"
     height  CDATA   "0"
     margin  CDATA   "0 0 0 0"
     padding CDATA   "0 0 0 0"
     rotation CDATA  "0"
     halign  (left|center|right|full)    "center"
     valign  (top|middle|bottom|full)    "middle"'>

<!ELEMENT elem1 (#PCDATA)>
<!ATTLIST elem1 %attrs;>

<!ELEMENT elem2 (#PCDATA)>
<!ATTLIST elem2 %attrs;>

这是另一个示例,其中混合了参数实体引用和仅出现在单个对象上的属性

Here's another example that has a mix of the parameter entity references along with attributes that only appear on the individual elements.

<!ELEMENT elem1 (#PCDATA)>
<!ATTLIST elem1 
    attr1 CDATA #IMPLIED
    %attrs;              >

<!ELEMENT elem2 (#PCDATA)>
<!ATTLIST elem2 
    attr2 CDATA #IMPLIED
    %attrs;              >

这篇关于如何声明多个元素共有的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆