
   namespace a = "http://relaxng.org/ns/compatibility/annotations/1.0"

   # xml2rfc Version 3 grammar

   rfc =
     element rfc {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute number { text }?,
       [ a:defaultValue = "" ] attribute obsoletes { text }?,
       [ a:defaultValue = "" ] attribute updates { text }?,
       attribute category { text }?,
       attribute mode { text }?,
       [ a:defaultValue = "false" ]
       attribute consensus { "no" | "yes" | "false" | "true" }?,
       attribute seriesNo { text }?,
       attribute ipr { text }?,
       attribute iprExtract { xsd:IDREF }?,
       [ a:defaultValue = "IETF" ]
       attribute submissionType {
         "IETF" | "IAB" | "IRTF" | "independent"
       }?,
       attribute docName { text }?,
       [ a:defaultValue = "false" ]
       attribute sortRefs { "true" | "false" }?,
       [ a:defaultValue = "true" ]
       attribute symRefs { "true" | "false" }?,
       [ a:defaultValue = "true" ]
       attribute tocInclude { "true" | "false" }?,
       [ a:defaultValue = "3" ] attribute tocDepth { text }?,
       attribute prepTime { text }?,
       [ a:defaultValue = "true" ]
       attribute indexInclude { "true" | "false" }?,
       attribute version { text }?,
       [ a:defaultValue = "Common,Latin" ] attribute scripts { text }?,
       attribute expiresDate { text }?,
       link*,
       front,
       middle,
       back?
     }

   link =
     element link {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute href { text },
       attribute rel { text }?
     }

   front =
     element front {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       title,
       seriesInfo*,
       author+,
       date?,
       area*,
       workgroup*,
       keyword*,
       abstract?,
       note*,
       boilerplate?
     }

   title =
     element title {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute abbrev { text }?,
       attribute ascii { text }?,
       text
     }

   author =
     element author {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute initials { text }?,
       attribute asciiInitials { text }?,
       attribute surname { text }?,
       attribute asciiSurname { text }?,
       attribute fullname { text }?,
       attribute role { "editor" }?,
       attribute asciiFullname { text }?,
       organization?,
       address?
     }

   organization =
     element organization {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute abbrev { text }?,
       attribute ascii { text }?,
       text
     }

   address =
     element address {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       postal?,
       phone?,
       facsimile?,
       email?,
       uri?
     }

   postal =
     element postal {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       ((city | code | country | region | street)* | postalLine+)
     }

   street =
     element street {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute ascii { text }?,
       text
     }

   city =
     element city {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute ascii { text }?,
       text
     }

   region =
     element region {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute ascii { text }?,
       text
     }

   code =
     element code {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute ascii { text }?,
       text
     }

   country =
     element country {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute ascii { text }?,
       text
     }

   postalLine =
     element postalLine {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute ascii { text }?,
       text
     }

   phone =
     element phone {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       text
     }

   facsimile =
     element facsimile {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       text
     }

   email =
     element email {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute ascii { text }?,
       text
     }

   uri =
     element uri {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       text
     }

   date =
     element date {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute day { text }?,
       attribute month { text }?,
       attribute year { text }?,
       empty
     }

   area =
     element area {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       text
     }

   workgroup =
     element workgroup {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       text
     }

   keyword =
     element keyword {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       text
     }

   abstract =
     element abstract {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute anchor { xsd:ID }?,
       attribute pn { text }?,
       (dl | ol | t | ul)+
     }

   note =
     element note {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute title { text }?,
       attribute pn { text }?,
       [ a:defaultValue = "false" ]
       attribute removeInRFC { "true" | "false" }?,
       name?,
       (dl | ol | t | ul)+
     }

   boilerplate =
     element boilerplate {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       section+
     }

   middle =
     element middle {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       section+
     }

   section =
     element section {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute anchor { xsd:ID }?,
       attribute pn { text }?,
       attribute title { text }?,
       [ a:defaultValue = "true" ]
       attribute numbered { "true" | "false" }?,
       [ a:defaultValue = "default" ]
       attribute toc { "include" | "exclude" | "default" }?,
       [ a:defaultValue = "false" ]
       attribute removeInRFC { "true" | "false" }?,
       name?,
       (artwork
        | aside
        | blockquote
        | dl
        | figure
        | iref
        | ol
        | sourcecode
        | t
        | table
        | texttable
        | ul)*,
       section*
     }

   name =
     element name {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute slugifiedName { text }?,
       (text | cref | eref | relref | tt | xref)*
     }

   t =
     element t {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute anchor { xsd:ID }?,
       attribute pn { text }?,
       attribute hangText { text }?,
       [ a:defaultValue = "false" ]
       attribute keepWithNext { "false" | "true" }?,
       [ a:defaultValue = "false" ]
       attribute keepWithPrevious { "false" | "true" }?,
       (text
        | bcp14
        | cref
        | em
        | eref
        | iref
        | \list
        | relref
        | spanx
        | strong
        | sub
        | sup
        | tt
        | vspace
        | xref)*
     }

   aside =
     element aside {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute anchor { xsd:ID }?,
       attribute pn { text }?,
       (artwork | dl | figure | iref | \list | ol | t | table | ul)*
     }

   blockquote =
     element blockquote {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute anchor { xsd:ID }?,
       attribute pn { text }?,
       attribute cite { text }?,
       attribute quotedFrom { text }?,
       ((artwork | dl | figure | ol | sourcecode | t | ul)+
        | (text
           | bcp14
           | cref
           | em
           | eref
           | iref
           | relref
           | strong
           | sub
           | sup
           | tt
           | xref)+)
     }

   \list =
     element list {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       [ a:defaultValue = "empty" ] attribute style { text }?,
       attribute hangIndent { text }?,
       attribute counter { text }?,
       attribute pn { text }?,
       t+
     }

   ol =
     element ol {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute anchor { xsd:ID }?,
       [ a:defaultValue = "1" ] attribute type { text }?,
       [ a:defaultValue = "1" ] attribute start { text }?,
       attribute group { text }?,
       [ a:defaultValue = "normal" ]
       attribute spacing { "normal" | "compact" }?,
       attribute pn { text }?,
       li+
     }

   ul =
     element ul {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute anchor { xsd:ID }?,
       [ a:defaultValue = "normal" ]
       attribute spacing { "normal" | "compact" }?,
       ([ a:defaultValue = "false" ]
        attribute empty { "false" | "true" },
        attribute pn { text }?)?,
       li+
     }

   li =
     element li {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute anchor { xsd:ID }?,
       attribute pn { text }?,
       ((artwork | dl | figure | ol | sourcecode | t | ul)+
        | (text
           | bcp14
           | cref
           | em
           | eref
           | iref
           | relref
           | strong
           | sub
           | sup
           | tt
           | xref)+)
     }

   dl =
     element dl {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute anchor { xsd:ID }?,
       [ a:defaultValue = "normal" ]
       attribute spacing { "normal" | "compact" }?,
       [ a:defaultValue = "true" ]
       attribute hanging { "false" | "true" }?,
       attribute pn { text }?,
       (dt, dd)+
     }

   dt =
     element dt {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute anchor { xsd:ID }?,
       attribute pn { text }?,
       (text
        | bcp14
        | cref
        | em
        | eref
        | iref
        | relref
        | strong
        | sub
        | sup
        | tt
        | xref)*
     }

   dd =
     element dd {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute anchor { xsd:ID }?,
       attribute pn { text }?,
       ((artwork | dl | figure | ol | sourcecode | t | ul)+
        | (text
           | bcp14
           | cref
           | em
           | eref
           | iref
           | relref
           | strong
           | sub
           | sup
           | tt
           | xref)+)
     }

   xref =
     element xref {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute target { xsd:IDREF },
       [ a:defaultValue = "false" ]
       attribute pageno { "true" | "false" }?,
       [ a:defaultValue = "default" ]
       attribute format { "default" | "title" | "counter" | "none" }?,
       attribute derivedContent { text }?,
       text
     }

   relref =
     element relref {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute target { xsd:IDREF },
       [ a:defaultValue = "of" ]
       attribute displayFormat { "of" | "comma" | "parens" | "bare" }?,
       attribute section { text },
       attribute relative { text }?,
       attribute derivedLink { text }?,
       text
     }

   eref =
     element eref {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute target { text },
       text
     }

   iref =
     element iref {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute item { text },
       [ a:defaultValue = "" ] attribute subitem { text }?,
       [ a:defaultValue = "false" ]
       attribute primary { "true" | "false" }?,
       attribute pn { text }?,
       empty
     }

   cref =
     element cref {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute anchor { xsd:ID }?,
       attribute source { text }?,
       [ a:defaultValue = "true" ]
       attribute display { "true" | "false" }?,
       (text | em | eref | relref | strong | sub | sup | tt | xref)*
     }

   tt =
     element tt {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       (text
        | bcp14
        | cref
        | em
        | eref
        | iref
        | relref
        | strong
        | sub
        | sup
        | xref)*
     }

   strong =
     element strong {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       (text
        | bcp14
        | cref
        | em
        | eref
        | iref
        | relref
        | sub
        | sup
        | tt
        | xref)*
     }

   em =
     element em {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       (text
        | bcp14
        | cref
        | eref
        | iref
        | relref
        | strong
        | sub
        | sup
        | tt
        | xref)*
     }

   sub =
     element sub {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       (text
        | bcp14
        | cref
        | em
        | eref
        | iref
        | relref
        | strong
        | tt
        | xref)*
     }

   sup =
     element sup {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       (text
        | bcp14
        | cref
        | em
        | eref
        | iref
        | relref
        | strong
        | tt
        | xref)*
     }

   spanx =
     element spanx {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       [ a:defaultValue = "preserve" ]
       attribute xml:space { "default" | "preserve" }?,
       [ a:defaultValue = "emph" ] attribute style { text }?,
       text
     }

   vspace =
     element vspace {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       [ a:defaultValue = "0" ] attribute blankLines { text }?,
       empty
     }

   figure =
     element figure {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute anchor { xsd:ID }?,
       attribute pn { text }?,
       [ a:defaultValue = "" ] attribute title { text }?,
       [ a:defaultValue = "false" ]
       attribute suppress-title { "true" | "false" }?,
       attribute src { text }?,
       attribute originalSrc { text }?,
       [ a:defaultValue = "left" ]
       attribute align { "left" | "center" | "right" }?,
       [ a:defaultValue = "" ] attribute alt { text }?,
       [ a:defaultValue = "" ] attribute width { text }?,
       [ a:defaultValue = "" ] attribute height { text }?,
       name?,
       iref*,
       preamble?,
       (artwork | sourcecode)+,
       postamble?
     }

   table =
     element table {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute anchor { xsd:ID }?,
       attribute pn { text }?,
       name?,
       iref*,
       thead?,
       tbody+,
       tfoot?
     }

   preamble =
     element preamble {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       (text
        | bcp14
        | cref
        | em
        | eref
        | iref
        | relref
        | spanx
        | strong
        | sub
        | sup
        | tt
        | xref)*
     }

   artwork =
     element artwork {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute anchor { xsd:ID }?,
       attribute pn { text }?,
       attribute xml:space { text }?,
       [ a:defaultValue = "" ] attribute name { text }?,
       [ a:defaultValue = "" ] attribute type { text }?,
       attribute src { text }?,
       [ a:defaultValue = "left" ]
       attribute align { "left" | "center" | "right" }?,
       [ a:defaultValue = "" ] attribute alt { text }?,
       [ a:defaultValue = "" ] attribute width { text }?,
       [ a:defaultValue = "" ] attribute height { text }?,
       attribute originalSrc { text }?,
       (text* | svg)
     }
   # https://www.rfc-editor.org/materials/format/SVG-1.2-RFC.rnc

   sourcecode =
     element sourcecode {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute anchor { xsd:ID }?,
       attribute pn { text }?,
       [ a:defaultValue = "" ] attribute name { text }?,
       [ a:defaultValue = "" ] attribute type { text }?,
       attribute src { text }?,
       attribute originalSrc { text }?,
       text
     }

   thead =
     element thead {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute anchor { xsd:ID }?,
       tr+
     }

   tbody =
     element tbody {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute anchor { xsd:ID }?,
       tr+
     }

   tfoot =
     element tfoot {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute anchor { xsd:ID }?,
       tr+
     }

   tr =
     element tr {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute anchor { xsd:ID }?,
       (td | th)+
     }

   td =
     element td {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute anchor { xsd:ID }?,
       [ a:defaultValue = "0" ] attribute colspan { text }?,
       [ a:defaultValue = "0" ] attribute rowspan { text }?,
       [ a:defaultValue = "left" ]
       attribute align { "left" | "center" | "right" }?,
       ((artwork | dl | figure | ol | sourcecode | t | ul)+
        | (text
           | bcp14
           | br
           | cref
           | em
           | eref
           | iref
           | relref
           | strong
           | sub
           | sup
           | tt
           | xref)*)
     }

   th =
     element th {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute anchor { xsd:ID }?,
       [ a:defaultValue = "0" ] attribute colspan { text }?,
       [ a:defaultValue = "0" ] attribute rowspan { text }?,
       [ a:defaultValue = "left" ]
       attribute align { "left" | "center" | "right" }?,
       ((artwork | dl | figure | ol | sourcecode | t | ul)+
        | (text
           | bcp14
           | br
           | cref
           | em
           | eref
           | iref
           | relref
           | strong
           | sub
           | sup
           | tt
           | xref)*)
     }

   postamble =
     element postamble {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       (text | cref | eref | iref | spanx | xref)*
     }

   texttable =
     element texttable {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute anchor { xsd:ID }?,
       [ a:defaultValue = "" ] attribute title { text }?,
       [ a:defaultValue = "false" ]
       attribute suppress-title { "true" | "false" }?,
       [ a:defaultValue = "center" ]
       attribute align { "left" | "center" | "right" }?,
       [ a:defaultValue = "full" ]
       attribute style { "all" | "none" | "headers" | "full" }?,
       name?,
       preamble?,
       ttcol+,
       c*,
       postamble?
     }

   ttcol =
     element ttcol {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute width { text }?,
       [ a:defaultValue = "left" ]
       attribute align { "left" | "center" | "right" }?,
       (cref | eref | iref | xref | text)*
     }

   c =
     element c {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       (text | cref | eref | iref | spanx | xref)*
     }

   bcp14 =
     element bcp14 {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       text
     }

   br =
     element br {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       empty
     }

   back =
     element back {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       displayreference*,
       references*,
       section*
     }

   displayreference =
     element displayreference {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute target { xsd:IDREF },
       attribute to { text }
     }

   references =
     element references {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute pn { text }?,
       attribute anchor { xsd:ID }?,
       attribute title { text }?,
       name?,
       (reference | referencegroup)*
     }

   reference =
     element reference {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute anchor { xsd:ID },
       attribute target { text }?,
       [ a:defaultValue = "true" ]
       attribute quoteTitle { "true" | "false" }?,
       front,
       (annotation | format | refcontent | seriesInfo)*
     }

   referencegroup =
     element referencegroup {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute anchor { xsd:ID },
       reference+
     }

   seriesInfo =
     element seriesInfo {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute name { text },
       attribute value { text },
       attribute asciiName { text }?,
       attribute asciiValue { text }?,
       attribute status { text }?,
       [ a:defaultValue = "IETF" ]
       attribute stream { "IETF" | "IAB" | "IRTF" | "independent" }?,
       empty
     }

   format =
     element format {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       attribute target { text }?,
       attribute type { text },
       attribute octets { text }?,
       empty
     }

   annotation =
     element annotation {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       (text
        | bcp14
        | cref
        | em
        | eref
        | iref
        | relref
        | spanx
        | strong
        | sub
        | sup
        | tt
        | xref)*
     }

   refcontent =
     element refcontent {
       attribute xml:base { text }?,
       attribute xml:lang { text }?,
       (text | bcp14 | em | strong | sub | sup | tt)*
     }
   start |= rfc

