Tecnologías XML / XML / XML in a Nutshell / Referencia XML / XML 1.1 : gramática de documentos

(Extracto de «XML in a Nutshell», de Elliotte Rusty Harold y W. Scott Means)

A continuación se presentan las reglas de producción en la forma extendida de Backus–Naur (EBNF) para la recomendación XML 1.1.

Gramática EBNF de XML 1.1

Documento

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

Intervalo de caracteres

[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]

espacios en blanco

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

Nombres y tokens

[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)*

Literales

[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] | [-'( )+,./:=?;!*#@$_%]

Datos de texto

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

Comentarios

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

Instrucciones de procesamiento

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

Secciones CDATA

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

Prólogo

[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

Definición de tipo de documento

[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

Subconjunto externo

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

Declaración de documento autónomo

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

Elemento

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

Etiqueta de apertura

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

Etiqueta de cierre

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

Contenido de elementos

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

Etiquetas de elementos vacíos

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

Declaración de tipo de elemento

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

Modelos de contenido de elementos

[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? ')'

Declaración de contenido mixto

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

Declaración de lista de atributos

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

Tipos de atributos

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

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

Tipos de atributos enumerados

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

Valores predeterminados de atributos

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

Secciones condicionales

[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*)

Referencia de carácter

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

Referencias a entidades

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

Declaración de entidad

[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

Declaración de entidad externa

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

Declaración de texto

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

Entidades externas analizadas bien formadas

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

Declaración de codificación

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

Declaración de notación

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

  

 

 

 

volver arriba