3. RELAX NG example

The RELAX NG example is similar to the other examples.

  1. Create a subdirectory named example3 in the addon/ subdirectory of XXE user preferences directory:

  2. Copy example3.rnc[4]to directory addon/example3/.

    default namespace = "http://www.xmlmind.com/xmleditor/schema/example3"
    namespace a = "http://relaxng.org/ns/compatibility/annotations/1.0"
    
    start = doc-element
    
    doc-element = element doc {
        para-element+
    }
    para-element = element para {
        mixed {
            [ a:defaultValue = "left" ]
            attribute align { "left" | "center" | "right" }?
        }
    }
  3. Copy example3.css to directory addon/example3/.

    @namespace url(http://www.xmlmind.com/xmleditor/schema/example3);
    
    doc,
    para {
        display: block;
    }
    para {
        margin: 1ex 0;
    }
    para[align] {
        text-align: concatenate(attr(align));
    }

    This style sheet would work fine without default namespace declaration at the top of it but rule matching is faster when @namespace is used.

  4. Create a document template for RELAX NG schema "http://www.xmlmind.com/xmleditor/schema/example3" using a text editor. Save it as addon/example3/example3.xml.

    <?xml version="1.0" encoding="UTF-8" ?>
    <doc xmlns="http://www.xmlmind.com/xmleditor/schema/example3">
      <para></para>
    </doc>

    Note that, unlike with DTDs and with W3C XML Schemas, there is no standard way to associate a RELAX NG schema to an instance[5].

  5. Create a configuration file for XXE. Save it as addon/example3/example3.xxe.

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <configuration name="Example3"
      xmlns="http://www.xmlmind.com/xmleditor/schema/configuration"
      xmlns:cfg="http://www.xmlmind.com/xmleditor/schema/configuration">
      <detect>
        <rootElementNamespace
          >http://www.xmlmind.com/xmleditor/schema/example3</rootElementNamespace>
      </detect>
    
      <relaxng compactSyntax="true" encoding="ISO-8859-1" location="example3.rnc"/>
    
      <css location="example3.css" name="Style sheet"/>
    
      <template location="example3.xml" name="Template"/>
    </configuration>

    The relaxng configuration element is essential because there is no standard way to associate a RELAX NG schema to an instance.

  6. Restart XXE.

    Now you can use FileNew and select Example3/Template to create a new document.

    Important

    Do not forget to temporarily disable the Schema cache (using OptionsPreferences, Schema tab, Enable cache toggle) if you intend to develop your own schema and test it using XXE.

  7. Make sure that the template document is valid: the red icon must not be displayed at the bottom/left of XXE window.

    If the template document, example3.xml, is invalid, please use a text editor and fix it because XXE is not designed to be comfortable to use with invalid documents.



[4] Example3.rng is also available in XXE_install_dir/doc/configure/samples/example3/, in case you prefer the XML syntax to the compact syntax.

[5] There is a non standard, proprietary, way to do that: the <?xxe-relaxng-schema location="..."?> processing instruction. However, its use should be restricted to testing and other quick and dirty experiments.