Technologies XML / XML / XML in a Nutshell / Référence XML / XML 1.1 : grammaire des documents

(Extrait de « XML in a Nutshell » d’Elliotte Rusty Harold & W. Scott Means)

Vous trouverez ci-dessous les règles de production en notation de Backus–Naur étendue (EBNF) pour la recommandation XML 1.1.

Grammaire EBNF de XML 1.1

Document

[1] document ::= prolog22 element39 Misc27* - Char2* RestrictedChar2a Char2*

Plage de caractères

[2] Char ::= [#x1-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] /* any Unicode character, excluding the surrogate blocks, FFFE, and FFFF. */ [2a] RestrictedChar ::= [#x1-#x8] | [#xB-#xC] | [#xE-#x1F] | [#x7F-#x84] | [#x86-#x9F]

espaces blancs

[3] S ::= (#x20 | #x9 | #xD | #xA)+

Noms et jetons

[4] NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF] [4a] NameChar ::= NameStartChar4 | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040] [5] Name ::= NameStartChar4 ( NameChar4a)* [6] Names ::= Name5 (#x20 Name5)* [7] Nmtoken ::= ( NameChar4a)+ [8] Nmtokens ::= Nmtoken7(#x20 Nmtoken7)*

Littéraux

[9] EntityValue ::= '"' ([^%&"] | PEReference69 | Reference67)* '"' | "'" ([^%&'] | PEReference69 | Reference67)* "'" [10] AttValue ::= '"' ([^<&"] | Reference67)* '"' | "'" ([^<&'] | Reference67)* "'" [11] SystemLiteral ::= ('"' [^"]* '"') | ("'" [^']* "'") [12] PubidLiteral ::= '"' PubidChar13* '"' | "'" ( PubidChar13 - "'")* "'" [13] PubidChar ::= #x20 | #xD | #xA | [a-zA-Z0-9] | [-'( )+,./:=?;!*#@$_%]

Données textuelles

[14] CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*)

Commentaires

[15] Comment ::= '<!--' (( Char2 - '-') | ('-' ( Char2 - '-')))* '-->'

Instructions de traitement

[16] PI ::= '<?' PITarget17( S3( Char2* - ( Char2* '?>' Char2*)))? '?>' [17] PITarget ::= Name5 - (('X' | 'x') ('M' | 'm') ('L' | 'l'))

Sections CDATA

[18] CDSect ::= CDStart19 CData20 CDEnd21 [19] CDStart ::= '<![CDATA[' [20] CData ::= ( Char2* - ( Char2* ']]>' Char2*)) [21] CDEnd ::= ']]>'

Prologue

[22] prolog ::= XMLDecl23 Misc27* ( doctypedecl28 Misc27*)? [23] XMLDecl ::= '<?xml' VersionInfo24 EncodingDecl80? SDDecl32? S3?'?>' [24] VersionInfo ::= S3 'version' Eq25("'" VersionNum26 "'" | '"' VersionNum26 '"') [25] Eq ::= S3? '=' S3? [26] VersionNum ::= '1.1' [27] Misc ::= Comment15 | PI16 | S3

Définition de type de document

[28] doctypedecl ::= '<!DOCTYPE' S3 Name5( S3 ExternalID)? S3? ('[' intSubset28b']' S3?)? '>' [28a] DeclSep ::= PEReference69 | S3 [28b] intSubset ::= ( markupdecl29 | DeclSep28a)* [29] markupdecl ::= elementdecl45 | AttlistDecl52 | EntityDecl70 | NotationDecl82 | PI16 | Comment15

Sous-ensemble externe

[30] extSubset ::= TextDecl77? extSubsetDecl31 [31] extSubsetDecl ::= ( markupdecl29 | conditionalSect61 | DeclSep28a)*

Déclaration de document autonome

[32] SDDecl ::= #x20+ 'standalone' Eq25(("'" ('yes' | 'no') "'") | ('"' ('yes' | 'no') '"'))

Élément

[39] element ::= EmptyElemTag44 | STag40 content43 ETag42

Balise ouvrante

[40] STag ::= '<' Name5 ( S3 Attribute41)* S3? '>' [41] Attribute ::= Name Eq AttValue

Balise fermante

[42] ETag ::= '</' Name5 S3? '>'

Contenu des éléments

[43] content ::= CharData14? (( element39 | Reference67 | CDSect18 | PI16 | Comment15) CharData14?)*

Balises d’éléments vides

[44] EmptyElemTag ::= '<' Name5( S3 Attribute41)* S3? '/>'

Déclaration de type d’élément

[45] elementdecl ::= '<!ELEMENT' S3 Name5 S3 contentspec46 S3? '>' [46] contentspec ::= 'EMPTY' | 'ANY' | 51 | children47

Modèles de contenu des éléments

[47] children ::= ( choice49 | seq50) ('?' | '*' | '+')? [48] cp ::= ( Name5 | choice49 | seq50) ('?' | '*' | '+')? [49] choice ::= '(' S3? cp48( S3? '|' S3? cp48)+ S3? ')' [50] seq ::= '(' S3? cp48( S3? ',' S3? cp48)* S3? ')'

Déclaration de contenu mixte

[51] Mixed ::= '(' S3? '#PCDATA' ( S3? '|' S3? Name5)* S3? ')*' | '(' S3? '#PCDATA' S3? ')'

Déclaration de liste d’attributs

[52] AttlistDecl ::= '<!ATTLIST' S3 Name5 AttDef53* S3? '>' [53] AttDef ::= S3 Name3 S3 AttType3 S3 DefaultDecl3

Types d’attributs

[54] AttType ::= StringType55 | TokenizedType56 | EnumeratedType57 [55] StringType ::= 'CDATA' [56] TokenizedType ::= 'ID'

| 'IDREF' 
| 'IDREFS' 
| 'ENTITY' 
| 'ENTITIES' 
| 'NMTOKEN' 
| 'NMTOKENS'

Types d’attributs énumérés

[57] EnumeratedType ::= NotationType58 | Enumeration59 [58] NotationType ::= 'NOTATION' S3'(' S3? Name5( S3? '|' S3? Name5)* S3? ')' [59] Enumeration ::= '(' S3? Nmtoken7( S3? '|' S3? Nmtoken7)* S3? ')'

Valeurs par défaut des attributs

[60] DefaultDecl ::= '#REQUIRED' | '#IMPLIED' | (('#FIXED' S3)? AttValue10)

Sections conditionnelles

[61] conditionalSect ::= includeSect62 | ignoreSect63 [62] includeSect ::= '<![' S3? 'INCLUDE' S3? '[' extSubsetDecl31']]>' [63] ignoreSect ::= '<![' S3? 'IGNORE' S3? '[' ignoreSectContents64* ']]>' [64] ignoreSectContents ::= Ignore65('<![' ignoreSectContents64']]>' Ignore65)* [65] Ignore ::= Char2* - ( Char2* ('<![' | ']]>') Char2*)

Référence de caractère

[66] CharRef ::= '&#' [0-9]+ ';' | '&#x' [0-9a-fA-F]+ ';'

Références d’entités

[67] Reference ::= EntityRef68 | CharRef66 [68] EntityRef ::= '&' Name5';' [69] PEReference ::= '%' Name5';'

Déclaration d’entité

[70] EntityDecl ::= GEDecl71 | PEDecl72 [71] GEDecl ::= '<!ENTITY' S3 Name5 S3 EntityDef73 S3? '>' [72] PEDecl ::= '<!ENTITY' S3'%' S3 Name5 S3 PEDef74 S3? '>' [73] EntityDef ::= EntityValue9 | ( ExternalID75 NDataDecl76?) [74] PEDef ::= EntityValue9 | ExternalID75

Déclaration d’entité externe

[75] ExternalID ::= 'SYSTEM' S3 SystemLiteral11 | 'PUBLIC' S3 PubidLiteral12 S3 SystemLiteral11 [76] NDataDecl ::= S3 'NDATA' S3 Name5

Déclaration de texte

[77] TextDecl ::= '<?xml' VersionInfo24? EncodingDecl80 S3? '?>'

Entités analysées externes bien formées

[78] extParsedEnt ::= TextDecl77? content43 - Char2* RestrictedChar2a Char2*

Déclaration d’encodage

[80] EncodingDecl ::= S3 'encoding' Eq25 ('"' EncName81'"' | "'" EncName81"'" ) [81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')* /* Encoding name contains only Latin characters */

Déclaration de notation

[82] NotationDecl ::= '<!NOTATION' S3 Name5 S3( ExternalID75 | PublicID83) S? '>' [83] PublicID ::= 'PUBLIC' S3 PubidLiteral12

  

 

 

 

haut de page