Home > other >  how to create Boolean attribute in XML DTD
how to create Boolean attribute in XML DTD

Time:07-26

I've never created a DTD before; I can barely read them in fact. I want to create an attribute that's either true or false. This is the best I have so far:

<!ATTLIST myElement
    someFlag CDATA #REQUIRED
>

But CDATA is quite a bit looser than just "true or false". I see here: https://en.wikipedia.org/wiki/Document_type_definition#Attribute_list_declarations There's an example that looks like I can enumerate the valid values so something like this should work:

<!ATTLIST myElement
    someFlag (true|false)
>

But that means I have to say "true|false" each type I need a bool? Is that right? Or am I totally confused? Is there any reasonably complete but approachable reference for this stuff, or do I have to just read the whole XML spec?

CodePudding user response:

A common DTD pattern is to define an entity for Boolean,

<!ENTITY % Boolean "(true|false)">

and then use it where needed:

<!ATTLIST myElement someFlag %Boolean;>
  • Related