2. W3C XML Schema example
Prev | Chapter 2. Writing a configuration file for XXE | Next

## 2. W3C XML Schema example

The W3C XML Schema example is similar to the DTD example.

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

2. Copy `example2.xsd` to directory `addon/example2/`.

       <?xml version='1.0' encoding='ISO-8859-1'?>
       <xs:schema elementFormDefault="qualified"
       targetNamespace="http://www.xmlmind.com/xmleditor/schema/example2"
       xmlns:xs="http://www.w3.org/2001/XMLSchema"
       xmlns:e2="http://www.xmlmind.com/xmleditor/schema/example2">
         <xs:element name="doc">
           <xs:complexType>
             <xs:sequence>
               <xs:element type="e2:Para" maxOccurs="unbounded" name="para"
               minOccurs="1"></xs:element>
             </xs:sequence>
           </xs:complexType>
         </xs:element>

         <xs:complexType name="Para" mixed="true">
           <xs:attribute default="left" name="align" type="e2:Align"></xs:attribute>
         </xs:complexType>

         <xs:simpleType name="Align">
           <xs:restriction base="xs:NMTOKEN">
             <xs:enumeration value="left"></xs:enumeration>
             <xs:enumeration value="center"></xs:enumeration>
             <xs:enumeration value="right"></xs:enumeration>
           </xs:restriction>
         </xs:simpleType>
       </xs:schema>

3. Copy `example2.css` to directory `addon/example2/`.

       @namespace url(http://www.xmlmind.com/xmleditor/schema/example2);

       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 XML Schema "`http://www.xmlmind.com/xmleditor/schema/example2`" using a text editor. Save it as `addon/example2/example2.xml`.

       <?xml version="1.0" encoding="UTF-8" ?>
       <doc xmlns="http://www.xmlmind.com/xmleditor/schema/example2"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://www.xmlmind.com/xmleditor/schema/example2
                             http://www.xmlmind.com/public/schema/example2.xsd">
         <para></para>
       </doc>

   It is highly recommended to use a public, absolute, URL such as "`http://www.xmlmind.com/public/schema/example2.xsd`" rather than relative URL "`example2.xsd`".

5. Using a text editor, create a XML catalog where URL "`http://www.xmlmind.com/public/schema/example2.xsd`" is associated to local file `example2.xsd`. Save it as `addon/example2/example2_catalog.xml`.

       <?xml version="1.0" ?>
       <catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"
                prefer="public">
         <uri name="http://www.xmlmind.com/public/schema/example2.xsd"
              uri="example2.xsd"/>
       </catalog>

   This catalog will spare XXE the effort of downloading W3C XML Schema `example2.xsd` from `http://www.xmlmind.com/public/schema/example2.xsd`.

6. Create a configuration file for XXE using XXE itself. Save it as `addon/example2/example2.xxe`.

       <?xml version='1.0' encoding='ISO-8859-1'?>
       <configuration name="Example2"
         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/example2</rootElementNamespace>
         </detect>

         <css name="Style sheet" location="example2.css" />

         <template name="Template" location="example2.xml" />
       </configuration>

   If you create a configuration file with a text editor, do not forget to check its validity before deploying it because, for performance reasons, XXE does not thoroughly validates its configuration files at start-up time. The simplest way to do that is to open the configuration file in XXE.

7. Restart XXE.

   Now you can use File|New and select Example2 > Template to create a new document.

   ### Important

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

8. 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, `example2.xml`, is invalid, please use a text editor and fix it because XXE is not designed to be comfortable to use with invalid documents.

About `addon/example2/example2.xxe`:

- detect: Simplest possible detection condition for a XML Schema based document: if a document opened by XXE has a root element in namespace "`http://www.xmlmind.com/xmleditor/schema/example2`" then XXE will automatically use configuration `addon/example2/example2.xxe`.

Prev | Up | Next
1. DTD example | Home | 3. RELAX NG example