XML - (Markup) Declaration (validation|constraint)

1 - About

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

declarations defined in the doctype:

These declarations may be contained in whole or in part within parameter entities

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>
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 (relationship)

element content model

Declaration Relationship (Cardinality)
<!ELEMENT master (child)> One and only once
<!ELEMENT master (child+)> One or more
<!ELEMENT master (child*)> Zero or more
<!ELEMENT master (child?)> Zero or one

Example:

<!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

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.

Example with doctype:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE TABLE [
        <!ELEMENT TABLE (ROW)*>
        <!ATTLIST ROW COL1 CDATA #IMPLIED>
        <!ATTLIST ROW COL2 CDATA #IMPLIED>
        <!ELEMENT ROW (#PCDATA)>
        ]>
<TABLE>
    <ROW COL1="25874" COL2="000005" />
    <ROW COL1="26084" COL2="000006" />
</TABLE>	

Data Science
Data Analysis
Statistics
Data Science
Linear Algebra Mathematics
Trigonometry

Powered by ComboStrap