DTD - spaces in (enumerated) attribute type list

Posted on 2004-10-27
Last Modified: 2013-11-19
Hi, I would like to have the following attribute list:

<!ATTLIST elementName attrName (two words|more than one word) #REQUIRED>

but it seems spaces are not valid in the enumerated list.  I also tried:

<!ENTITY % twoWords "two words">
<!ENTITY % moreThanOneWord "more than one word">
<!ATTLIST elementName attrName(%twoWords;|%moreThanOneWord;) #REQUIRED>

but was also unable to validate the DTD.  How can I solve this?  Thanks.
Question by:pw05
    LVL 26

    Accepted Solution

    DTD's are quite limited in what they can do.  Attributes can only have a few datatypes.  The enumerated type only allows name tokens (NMTOKEN).  You can use a NOTATION type for an attribute, then specify (using a <!NOTATION> declaration) an external reference, but I don't think you'll be able to validate that way.  Notation is mainly used to help an external application understand a custom datatype.  For example, you might declare a notation to assist your external application in handling an unparsed external entity, such as an image file in JPEG or GIF file format.

    You're really better of defining this sort of thing in a Schema, such as a W3C XML Schema.

    Mike Sharp
    LVL 26

    Expert Comment

    I didn't explicitly say, but you've probably already realized, a NMTOKEN is a single word, with no whitespace.  They are essentially like character data (CDATA) except they cannot contain whitespace characters such as space, tab, newline etc.  

    Mike Sharp

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    Course: Foundations of Front-End Development

    Jump-start a lucrative career in front-end web development, with zero previous coding experience required. This course covers the basic programming concepts and languages required for creating engaging websites from scratch.

    Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
    JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    860 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now