Search code examples
xmldtd

XML attribute required with empty value


I've set the attribut "number" to #REQUIRED, but is an empty value valid?

DTD:

<!ATTLIST person number CDATA #REQUIRED>

XML:

<person number="" />

Solution

  • Yes, an empty value suffices to meet the #REQUIRED constraint on an XML attribute. The value of the attribute is irrelevant; the presence of the attribute is all that's required:

    Validity constraint: Required Attribute

    If the default declaration is the keyword #REQUIRED, then the attribute must be specified for all elements of the type in the attribute-list declaration.