RELAX NG by Eric van der Vlist will be published by O'Reilly & Associates (ISBN: 0596004214)

You are welcome to use our annotation system to give your feedback.


Escaping named pattern identifiers in the compact syntax

In the last chapter, Chapter 4: Non XML Syntax, we introduced the compact syntax and noted that any word reserved for use by RELAX NG could be used as an element or attribute name. That's no longer the case for the identifiers of named patterns since they can appear in the same position as the keywords.

If we wanted to define a named pattern named "text", "start" or "element" for instance, the identifier of this named pattern could be confused with the keyword. In this case we need to escape being confused with the identifier by a leading "\". For instance to define (and by extension to make a reference) to a named pattern named "start", we would write:

 grammar{
    
 start = \start
    
 \start = element start { text }
    
 }

And in the XML syntax, this would translate as:

 <?xml version="1.0" encoding="UTF-8"?>
 <grammar xmlns="http://relaxng.org/ns/structure/1.0">
   <start>
     <ref name="start"/>
   </start>
   <define name="start">
     <element name="start">
       <text/>
     </element>
   </define>
 </grammar>

You are welcome to use our annotation system to give your feedback.
[Annotations for this page]
All text is copyright Eric van der Vlist, Dyomedea. During development, I give permission for non-commercial copying for educational and review purposes. After publication, all text will be released under the Free Software Foundation GFDL.