How do I declare attributes common to multiple elements?
Asked Answered
C

1

8

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

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

(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?)

Cantu answered 1/12, 2013 at 3:22 Comment(0)
C
10

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

Example...

<!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;              >
Ctenidium answered 1/12, 2013 at 7:58 Comment(2)
@MichałKrzysztofFeiler - Take a look at oXygen XML Editor. It's not free, but it's worth every penny. They also have an evaluation license and an academic license.Ctenidium
It appears that not only xmllint doesn't accept that, but using these in XML given to Firefox or Chrome also results in errors… Firefox straight out says it is an illegal parameter entity reference, Chrome gives a result more similar to the one from xmllintHuba

© 2022 - 2024 — McMap. All rights reserved.