xmldtd

Can you use a forward slash "/" in an XML attribute value via DTD?


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.


Solution

  • 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>
    ]>