XML - Declaration (validation|constraint)

> Markup Language (ML) > Extensible Markup Language (XML)

1 - About

The element structure of an XML document may, for validation purposes, be constrained using:

declarations.

Advertising

3 - Declaration Type

3.1 - Element type

3.1.1 - Definition

An element type declaration constrains the element's content.

Element type declarations often constrain which element types can appear as children of the element.

An XML processor may issue a warning when a declaration mentions an element type for which no declaration is provided, but this is not an error.

3.1.2 - Syntax

<!ELEMENT Name contentspec>

where:

  • name gives the element type
  • contentspec is one of the following specification:
3.1.2.1 - empty

empty element declaration

<!ELEMENT br EMPTY>
Advertising
3.1.2.2 - any
<!ELEMENT container ANY>
3.1.2.3 - mixed

mixed content declarations:

<!ELEMENT p (#PCDATA|a|ul|b|i|em)*>
<!ELEMENT p (#PCDATA | %font; | %phrase; | %special; | %form;)* >
<!ELEMENT b (#PCDATA)>

The keyword #PCDATA derives historically from the term “parsed character data.”

3.1.2.4 - children

element content model

<!ELEMENT spec (front, body, back?)>
<!ELEMENT div1 (head, (p | list | note)*, div2*)>
<!ELEMENT dictionary-body (%div.mix; | %dict.mix;)*>

where the cardinality operator:

  • one or more (+),
  • zero or more (*),
  • or zero or one times (?).
  • (default|absence): once
Advertising

3.2 - Attribute-list

Attribute-list declarations specify:

  • the name,
  • data type,
  • and default value (if any)

of each attribute associated with a given element type.