XML Attribute Declaration

The XML ATTLIST declaration defines the attributes that an XML element can have.

The syntax for attribute declarations specified in the XML standard is:

<!ATTLIST ElementName AttributeName TokenizedType | CDATA | ValueList {#REQUIRED|#FIXED|#IMPLIED} DefaultValue>

Meaning

  • ElementName—name of the element to which the attribute belongs
  • AttributeName—name of the attribute
  • TokenizedType—for example, a unique ID number, or the name of an entity declared within the XML document
  • CDATA—string data
  • ValueList—list of optional values, with the following structure: (Value1 | Value2 | Valuen ...)
  • #REQUIRED —declares the attribute is always present with a value
  • #FIXED —declares that the attribute is always present and always has the default value. Fixed attributes can be used to declare namespaces for element names.
  • #IMPLIED—declares that no default value is provided for the attribute
  • DefaultValue—default value of the attribute. A default value cannot be specified for #REQUIRED or #IMPLIED attributes.

Description

The XML standard allows an alternative syntax for attribute declarations, whereby all attributes are declared for an element in one <!ATTLIST> declaration.

XML Structs

In an XML-based Struct, an XML attribute is represented as a Struct with the same name as the element for which it is declared, with the xmlClass tag set to attlist-declaration. This Struct is a sibling to the element-declaration Struct of the same name.

Each attribute declared in the ATTLIST, is represented as a member of its parent attlist-declaration Struct, with the xmlClass set to attribute-declaration.

For each attribute, the xmlDataType and xmlAttrMode annotations may also be set.

Conversion to Structs

For example, the following extract from a DOCTYPE declaration contains an element movie and two attribute declarations defining three attributes—id, xml, and director:

...
    <!ELEMENT movie (title+, director, genre*, review)>
    <!ATTLIST movie id ID #IMPLIED
                    xml:lang NMTOKEN "EN">
    <!ATTLIST movie year CDATA  #IMPLIED>
...

When converted using xmlToStruct/full, the resulting Struct contains three member Structs representing the movie element and its attributes:

    [movie] = "(title+,director,genre*,review)"
      [$tags]
        [xmlClass] = element-declaration
    [movie]
      [$tags]
        [xmlClass] = attlist-declaration
      [id] = ""
        [$tags]
          [xmlClass] = attribute-declaration
          [xmlDataType] = ID
          [xmlAttrMode] = #IMPLIED
      [xml:lang] = "EN"
        [$tags]
          [xmlClass] = attribute-declaration
          [xmlDataType] = NMTOKEN
    [movie]
      [$tags]
        [xmlClass] = attlist-declaration
      [year] = ""
        [$tags]
          [xmlClass] = attribute-declaration
          [xmlDataType] = CDATA
          [xmlAttrMode] = #IMPLIED

Uniface XML Streams

The alternative <!ATTLIST> syntax is not supported for Uniface XML streams. For more information on attribute declarations for Uniface-compliant XML streams, see Uniface-Compliant Attribute Declarations.

Related Topics