2

I have an atribute named item_category and I want to use as enumerated values ( h/w | s/w). Is that possible? And If it is how? Basically i tried:

<!ATTLIST item
    item_category (h/w | s/w) #REQUIRED>

but I get errors like Expecting "|". and Missing attribute presence #IMPLIED, #Required... and Expecting ")". so it actually doesnt take forward slash as a value.

Toulis
  • 120
  • 2
  • 9
  • Using it's html entity ? `h/w | s/w` – LMC May 30 '22 at 13:55
  • @LMC: That's not going to help -- still not allowed in an XML attribute name. – kjhughes May 30 '22 at 13:57
  • OP is asking about enumerations for the attribute value, not the name. – Mads Hansen May 30 '22 at 14:03
  • Well, at least that what is the *code* is attempting to do. @Toulis you may want to update the question to clarify that you are asking about attribute values, not names. – Mads Hansen May 30 '22 at 14:08
  • @MadsHansen: Oops, I see that you're right that OP was asking about attribute values, not names -- my mistake. Thanks for answering the actual question asked. ;-) – kjhughes May 30 '22 at 15:21

1 Answers1

1

I don't think that you can directly.

The values for an enumeration in an ATTLIST have to be either NOTATION or NMTOKEN.

https://www.w3.org/TR/REC-xml/#NT-AttlistDecl

[Definition: Enumerated attributes have a list of allowed values in their declaration ]. They must take one of those values. There are two kinds of enumerated attribute types:

Enumerated Attribute Types [57] EnumeratedType ::= NotationType | Enumeration

[58] NotationType ::= 'NOTATION' S '(' S? Name (S? '|' S? Name)* S? ')' [VC: Notation Attributes] [VC: One Notation Per Element Type] [VC: No Notation on Empty Element] [VC: No Duplicate Tokens]

[59] Enumeration ::= '(' S? Nmtoken (S? '|' S? Nmtoken)* S? ')' [VC: Enumeration] [VC: No Duplicate Tokens]

A / isn't allowed in the value of an NMTOKEN.

It is allowed as the value of a NOTATION.

<!NOTATION hw PUBLIC "h/w">
<!NOTATION sw PUBLIC "s/w">
<!ATTLIST item
    item_category NOTATION (hw|sw) #REQUIRED>
]>
Mads Hansen
  • 63,927
  • 12
  • 112
  • 147