Notes about XML







Online resources


The following link points to an online XSD Schema Validator. You can use it to validate XML document against XSD file (schema).



Namespaces


What Does a Namespace URL Locate?

The W3C has an answer to this question: There is nothing at all at the end of a namespace URI, except perhaps a 404 Not Found error. One reason the W3C wanted to avoid putting anything at the end of a namespace URI is that it wasn't clear what to put there. Should it be a DTD? a schema? a Java-content handler for processing the document? a style sheet? something else? There are simply too many good choices to limit developers to any one of these.

Unfortunately, this answer seems to be one that developers are unable or unwilling to hear. With few exceptions, namespace URIs are URLs, Uniform Resource Locators, and it's not unreasonable for users to expect a URL to locate a resource. However, namespace URLs are identifiers, not locators. Thus, the error logs of the W3C and other purveyors of XML specifications have been filling up with requests for nonexistent pages at the end of namespace URLs, and XML mailing lists are besieged with questions about whether one can run an XML parser on a machine that isn't connected to the Internet and is thus unable to resolve the namespace URL.


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<!--
      The child's elements "DESCRIPTION" and "AGE" from the category "AUTO" and "MOTO"
      are not identical regarding the DTD.
--->



<VENTE>

  <automobile:AUTO xmlns:automobile="http://automobile.org" color="red" prix="1000">
     <automobile:DESCRIPTION>Audi TT d'occasion</automobile:DESCRIPTION>
     <automobile:AGE>17 ans</automobile:AGE>
  </automobile:AUTO>

  <motocycle:MOTO xmlns:motocycle="http://motocycle.org" color="blue" prix="500">
     <motocycle:DESCRIPTION>BMW 50e</motocycle:DESCRIPTION>
     <motocycle:AGE>5 ans</motocycle:AGE>
  </motocycle:MOTO>

</VENTE>



DTD



<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<!DOCTYPE TEST [

<!ELEMENT TEST (ELEMENT1, ELEMENT2)>

<!ELEMENT ELEMENT1 EMPTY>
<!ATTLIST ELEMENT1 attribut1 CDATA #REQUIRED>
<!ATTLIST ELEMENT1 attribut2 CDATA "default value">


<!ELEMENT ELEMENT2 (#PCDATA)>

]>

<TEST>
  <ELEMENT1 attribut1="value"/>
  <ELEMENT2>Text that will be parsed</ELEMENT2>
</TEST>

<TEST>
  <ELEMENT1 attribut1="value" attribut2="value"/>
  <ELEMENT2>Text that will be parsed</ELEMENT2>
</TEST>


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<!DOCTYPE TEST [

<!ELEMENT TEST (ELEMENT1+, ELEMENT2)>

<!ELEMENT ELEMENT1 EMPTY>
<!ATTLIST ELEMENT1 attribut1 CDATA #REQUIRED>
<!ATTLIST ELEMENT1 attribut2 CDATA "default value">


<!ELEMENT ELEMENT2 (#PCDATA)>

]>


The "+" means that the element can appear at least one time in the document.



<TEST>
  <ELEMENT1 attribut1="value" attribut2="value"/>
  <ELEMENT2>Text that will be parsed</ELEMENT2>
</TEST>

<TEST>
  <ELEMENT1 attribut1="value1" attribut2="value"/>
  <ELEMENT1 attribut1="value2"/>
  <ELEMENT1 attribut1="value3"/>
  <ELEMENT2>Text that will be parsed</ELEMENT2>
</TEST>


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<!DOCTYPE TEST [

<!ELEMENT TEST (ELEMENT1*, ELEMENT2)>

<!ELEMENT ELEMENT1 EMPTY>
<!ATTLIST ELEMENT1 attribut1 CDATA #REQUIRED>
<!ATTLIST ELEMENT1 attribut2 CDATA "default value">


<!ELEMENT ELEMENT2 (#PCDATA)>

]>


The "*" means that the element can appear zero or more time in the document.



<TEST>
  <ELEMENT1 attribut1="value1" attribut2="value"/>
  <ELEMENT1 attribut1="value2"/>
  <ELEMENT1 attribut1="value3"/>
  <ELEMENT2>Text that will be parsed</ELEMENT2>
</TEST>

<TEST>
  <ELEMENT2>Text that will be parsed</ELEMENT2>
</TEST>


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>


<!DOCTYPE TEST [

<!ELEMENT TEST (ELEMENT1?, ELEMENT2)>

<!ELEMENT ELEMENT1 EMPTY>
<!ATTLIST ELEMENT1 attribut1 CDATA #REQUIRED>
<!ATTLIST ELEMENT1 attribut2 CDATA "default value">


<!ELEMENT ELEMENT2 (#PCDATA)>

]>
The "?" means that the element can appear zero or one (and only one) time in the document.

<TEST>
  <ELEMENT1 attribut1="value1" attribut2="value"/>
  <ELEMENT2>Text that will be parsed</ELEMENT2>
</TEST>


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<!DOCTYPE TEST [

<!ELEMENT TEST (ELEMENT1?, ELEMENT2)>

<!ELEMENT ELEMENT1 ANY>

<!ATTLIST ELEMENT1 attribut1 CDATA #REQUIRED>
<!ATTLIST ELEMENT1 attribut2 CDATA "default value">
<!ELEMENT ELEMENT2 (#PCDATA)>


]>
"ANY" means that the element can contain anything: text or child elements.

<TEST>
  <ELEMENT1 attribut1="value1" attribut2="value"/>
  <ELEMENT2>Text that will be parsed</ELEMENT2>
</TEST>

<TEST>
  <ELEMENT1 attribut1="value1" attribut2="value">Text</ELEMENT1>
  <ELEMENT2>Text that will be parsed</ELEMENT2>
</TEST>

<TEST>
  <ELEMENT1 attribut1="value1" attribut2="value">
     Text
     <ELEMENT2>Text that will be parsed</ELEMENT2>
  </ELEMENT1>
  <ELEMENT2>Text that will be parsed</ELEMENT2>
</TEST>

<TEST>
  <ELEMENT1 attribut1="value1" attribut2="value">
     Text
     <ELEMENT2>Text that will be parsed</ELEMENT2>
     <ELEMENT2>Text that will be parsed</ELEMENT2>
  </ELEMENT1>
  <ELEMENT2>Text that will be parsed</ELEMENT2>
</TEST>


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<!DOCTYPE TEST [

<!ELEMENT TEST (ELEMENT1)>

<!ELEMENT ELEMENT1 EMPTY>
<!ATTLIST ELEMENT1 attribut1 CDATA #REQUIRED>
<!ATTLIST ELEMENT1 attribut2 CDATA "default value">
<!ATTLIST ELEMENT1 color (red | green | blue) #IMPLIED>


]>


The optional attribute "color" may take one of the 3 values 'red', 'green' or 'blue'.



<TEST>
  <ELEMENT1 attribut1="value1" attribut2="value" color="red"/>
</TEST>

<TEST>
  <ELEMENT1 attribut1="value1" attribut2="value"/>
</TEST>


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>


<!DOCTYPE TEST [

<!ELEMENT TEST (ELEMENT1)>

<!ELEMENT ELEMENT1 EMPTY>
<!ATTLIST ELEMENT1 attribut1 CDATA #REQUIRED>
<!ATTLIST ELEMENT1 attribut2 CDATA "default value">
<!ATTLIST ELEMENT1 color (red | green | blue) "green">


]>


If the attribute "color" is not specified, the default value for this attribute is 'green'.



<TEST>
  <ELEMENT1 attribut1="value1" attribut2="value"/>
</TEST>

<TEST>
  <ELEMENT1 attribut1="value1" attribut2="value" color="blue"/>
</TEST>


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<!DOCTYPE TEST [
<!ELEMENT TEST (ELEMENT1, ELEMENT2)>

<!ELEMENT ELEMENT1 EMPTY>
<!ATTLIST ELEMENT1 anchor ID #REQUIRED>


<!ELEMENT ELEMENT2 EMPTY>
<!ATTLIST ELEMENT2 link_to IDREF #REQUIRED>


]>


IDREF defines a link to ID. All IDREF must have an corresponding ID.



<TEST>
  <ELEMENT1 anchor="arrivee" />
  <ELEMENT2 link_to="arrivee" />
</TEST>


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<!DOCTYPE TEST [

<!ELEMENT TEST (ELEMENT1+, ELEMENT2+)>

<!ELEMENT ELEMENT1 EMPTY>
<!ATTLIST ELEMENT1 anchor ID #REQUIRED>


<!ELEMENT ELEMENT2 EMPTY>
<!ATTLIST ELEMENT2 link_to IDREF #REQUIRED>


]>

<TEST>

  <ELEMENT1 anchor="chez_moi" />
  <ELEMENT1 anchor="au_travail" />
  <ELEMENT1 anchor="a_la_piscine" />

  <ELEMENT2 link_to="chez_moi" />
  <ELEMENT2 link_to="chez_moi" />
  <ELEMENT2 link_to="au_travail" />
  <ELEMENT2 link_to="a_la_piscine" />

</TEST>


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>


<!DOCTYPE TEST [
<!ELEMENT TEST (ELEMENT1+, ELEMENT2+)>

<!ELEMENT ELEMENT1 EMPTY>
<!ATTLIST ELEMENT1 anchor ID #REQUIRED>


<!ELEMENT ELEMENT2 EMPTY>
<!ATTLIST ELEMENT2 link_to IDREFS #IMPLIED>


]>

IDREFS defines a link to several targets. Targets are separated by spaces.

<TEST>

  <ELEMENT1 anchor="chez_moi" />
  <ELEMENT1 anchor="au_travail" />
  <ELEMENT1 anchor="a_la_piscine" />

  <ELEMENT2 link_to="chez_moi" />
  <ELEMENT2 link_to="chez_moi" />
  <ELEMENT2 link_to="au_travail a_la_piscine" />
  <ELEMENT2 />

</TEST>


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<!DOCTYPE TEST [

<!ELEMENT TEST (ELEMENT1)>

<!ELEMENT ELEMENT1 EMPTY>
<!ATTLIST ELEMENT1 attribute CDATA #FIXED "valeur fixe">

]>
The attribute "attribute" can take only one value: "valeur fixe".

<TEST>

  <ELEMENT1 attribute="valeur fixe" />

</TEST>


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>


<!DOCTYPE TEST [

<!ENTITY signature "Your sugnature">
<!ENTITY header "Document header">


<!ELEMENT TEST (ELEMENT1)>

<!ELEMENT ELEMENT1 (#PCDATA)>
<!ATTLIST ELEMENT1 attribute CDATA #FIXED "valeur fixe">

]>

<TEST>

  <ELEMENT1 attribute="valeur fixe">&signature;</ELEMENT1>

</TEST>


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>


<!--

     This eample illustrates the use of NMTOKEN and NMTOKENS.
     NMTOKEN type can contain only letters, digits and point [ . ] , hyphen [ - ], underline [ _ ] and colon [ : ].
     NMTOKENS can contain the same characters as NMTOKEN plus whitespaces. White space consists of one or more space characters, carriage returns, line feeds, or tabs.

-->

<!DOCTYPE TEST
[

  <!ELEMENT TEST (ELEMENT1 | ELEMENT2)>

  <!ELEMENT ELEMENT1 EMPTY>
  <!ATTLIST ELEMENT1 attribute NMTOKEN #REQUIRED>


  <!ELEMENT ELEMENT2 EMPTY>
  <!ATTLIST ELEMENT2 attribute NMTOKENS #REQUIRED>


]>

<TEST>
   <ELEMENT1 attribute="toto" />
</TEST>

<TEST>
   <ELEMENT2 attribute="toto titi" />
</TEST>


Schemas


  • XML Schemas define the elements of your XML files.
  • A simple element is an XML element that can contain only text. It cannot contain any other elements or attributes.
  • All attributes are declared as simple types.
  • Only complex elements can have attributes.
  • Restrictions are used to control acceptable values for XML elements or attributes. Restrictions on XML elements are called facets.
  • A complex element contains other elements and/or attributes.



Simple element with text only/A>



<?xml version="1.0"?>


<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="http://target.org"
           xmlns="http://target.org"
           elementFormDefault="qualified">


     <xs:element name="configuration" type="xs:string"/>


</xs:schema>

<?xml version="1.0"?>

<configuration xmlns="http://target.org"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://target.org test2.xsd">


123

</configuration>



Complex element with simple elements only (no attribute, no text)



<?xml version="1.0"?>

<!-- The <schema> element is the root element of every XML Schema -->
<!-- -->
<!-- Elements and data types used in the schema (schema, element, -->
<!-- complexType, sequence, string, boolean, etc.) come from the -->
<!-- "http://www.w3.org/2001/XMLSchema" namespace. -->
<!-- Do not use any other URL (this is hard coded is the parser) -->
<!-- -->
<!-- Elements affected by this schema come from the -->
<!-- "http://target.org" namespace. -->
<!-- -->
<!-- The default namespace is "http://target.org". -->
<!-- -->

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="http://target.org"
           xmlns="http://target.org"
           elementFormDefault="qualified">



<!-- Define all simple types -->
<!-- -->
<!-- timeout value can only vary from 0 to 100. -->
<!-- level value can only be 'info', 'warning' or 'error'. -->
<!-- An ID begins with 4 uppercase letters followed by one or -->
<!-- integers. -->

     <xs:simpleType name="timeouttype">
        <xs:restriction base="xs:integer">
          <xs:minInclusive value="0"/>
          <xs:maxInclusive value="100"/>
        </xs:restriction>
     </xs:simpleType>

     <xs:simpleType name="level">
       <xs:restriction base="xs:string">
         <xs:enumeration value="info"/>
         <xs:enumeration value="warning"/>
         <xs:enumeration value="error"/>
       </xs:restriction>
     </xs:simpleType>

     <xs:simpleType name="idtype">
       <xs:restriction base="xs:string">
         <xs:pattern value="[A-Z]{4}[0-9]+"/>
       </xs:restriction>
     </xs:simpleType>

<!-- Now, define the root node that contains the document. -->
<!-- This is a comple element that contains other elements and -->
<!-- Base types 'timeouttype', 'level' and 'idtype' are previous- -->
<!-- -ly declared. -->

     <xs:element name="note">
       <xs:complexType>
         <xs:sequence>
            <xs:element name="description" type="xs:string"/>
            <xs:element name="timeout" type="timeouttype"/>
            <xs:element name="errorlevel" type="level"/>
            <xs:element name="ID" type="idtype"/>
         </xs:sequence>
       </xs:complexType>
     </xs:element>

</xs:schema>

<?xml version="1.0"?>

<!-- xmlns="http://target.org": default namespace for this document. -->
<!-- -->
<!-- xmlns:xsi="http://shema.org-instance": Create an instance of -->
<!-- the schema used to validate this document. -->
<!-- -->
<!-- xsi:schemaLocation="http://target.org test1.xsd": the document -->
<!-- "test1.xsd" contains the schema used to validate the XML docu- -->
<!-- -ment. "http://target.org" is the target namesapce for the -->
<!-- validation. -->


<!-- REMARKS: -->
<!-- * The declaration order for elements 'description', 'timeout' -->
<!-- 'errorlevel' and 'ID' is important. -->
<!-- * The namespace "http://target.org" is important (the schema -->
<!-- works for this namespace and no other). -->
<!-- * test1.xsd is the file that contains the schema. -->


<note xmlns="http://target.org"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://target.org test1.xsd">

      <description>This job is used to purge the mailboxes.</description>

      <timeout>5</timeout>

      <errorlevel>info</errorlevel>

      <ID>AZER0</ID>
</note>



Complex element with complex and simple elements only (no attribute, no text)


The following example is a little bit more complex. A complex element contains another complex element.


<?xml version="1.0"?>

<!-- The <schema> element is the root element of every XML Schema -->
<!-- -->
<!-- Elements and data types used in the schema (schema, element, -->
<!-- complexType, sequence, string, boolean, etc.) come from the -->
<!-- "http://shema.org" namespace. -->
<!-- -->
<!-- Elements affected by this schema come from the -->
<!-- "http://target.org" namespace. -->
<!-- -->
<!-- The default namespace is "http://target.org". -->
<!-- -->

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="http://target.org"
           xmlns="http://target.org"
           elementFormDefault="qualified">



<!-- Define all simple types -->
<!-- -->
<!-- timeout value can only vary from 0 to 100. -->
<!-- level value can only be 'info', 'warning' or 'error'. -->
<!-- An ID begins with 4 uppercase letters followed by one or -->
<!-- integers. -->

     <xs:simpleType name="timeouttype">
        <xs:restriction base="xs:integer">
          <xs:minInclusive value="0"/>
          <xs:maxInclusive value="100"/>
        </xs:restriction>
     </xs:simpleType>

     <xs:simpleType name="level">
       <xs:restriction base="xs:string">
         <xs:enumeration value="info"/>
         <xs:enumeration value="warning"/>
         <xs:enumeration value="error"/>
       </xs:restriction>
     </xs:simpleType>

     <xs:simpleType name="idtype">
       <xs:restriction base="xs:string">
         <xs:pattern value="[A-Z]{4}[0-9]+"/>
       </xs:restriction>
     </xs:simpleType>

<!-- Now, define the root node that contains the document. -->
<!-- This is a comple element that contains other elements and -->
<!-- Base types 'timeouttype', 'level' and 'idtype' are previous- -->
<!-- -ly declared. -->

     <xs:element name="job">
       <xs:complexType>
         <xs:sequence>

           <xs:element name="title" type="xs:string"/>

           <xs:element name="note">
             <xs:complexType>
               <xs:sequence>
                 <xs:element name="description" type="xs:string"/>
                 <xs:element name="timeout" type="timeouttype"/>
                 <xs:element name="errorlevel" type="level"/>
                 <xs:element name="ID" type="idtype"/>
               </xs:sequence>
             </xs:complexType>
           </xs:element>

         </xs:sequence>
       </xs:complexType>
     </xs:element>


</xs:schema>

<?xml version="1.0"?>

<!-- xmlns="http://target.org": default namespace for this document. -->
<!-- -->
<!-- xmlns:xsi="http://shema.org-instance": Create an instance of -->
<!-- the schema used to validate this document. -->
<!-- -->
<!-- xsi:schemaLocation="http://target.org test1.xsd": the document -->
<!-- "test1.xsd" contains the schema used to validate the XML docu- -->
<!-- -ment. "http://target.org" is the target namesapce for the -->
<!-- validation. -->


<!-- REMARKS: -->
<!-- * The declaration order for elements 'description', 'timeout' -->
<!-- 'errorlevel' and 'ID' is important. -->
<!-- * The namespace "http://target.org" is important (the schema -->
<!-- works for this namespace and no other). -->

<job xmlns="http://target.org"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://target.org test1.xsd">

      <title>This is the title</title>

      <note>
           <description>This job is used to purge the mailboxes.</description>

           <timeout>5</timeout>

           <errorlevel>info</errorlevel>

          <ID>AZER0</ID>
      </note>

</job>



Complex element with attributes only (no text)



<?xml version="1.0"?>


<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="http://target.org"
           xmlns="http://target.org"
           elementFormDefault="qualified">



<!-- Define simple types -->

     <xs:simpleType name="timeouttype">
        <xs:restriction base="xs:integer">
          <xs:minInclusive value="0"/>
          <xs:maxInclusive value="100"/>
        </xs:restriction>
     </xs:simpleType>

<!-- Define attributes -->
<!-- Note: all attributes are optional by default -->

     <xs:element name="configuration">
       <xs:complexType>
         <xs:sequence>

           <xs:element name="job">
             <xs:complexType>

             <!-- Define attributes for the element "job". -->
             <!-- Attributes are optional by default. -->

                  <xs:attribute name="name" type="xs:string" use="required"/>
                  <xs:attribute name="timeout" type="timeouttype"/>
                  <xs:attribute name="active" type="xs:boolean" default="false"/>

             </xs:complexType>
           </xs:element>

         </xs:sequence>
       </xs:complexType>
     </xs:element>

</xs:schema>

<?xml version="1.0"?>

<configuration xmlns="http://target.org"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://target.org test2.xsd">

               <!-- The attribute "timeout" is optional (no default value). -->
               <!-- The attribute "active" is optional (default value is "false") -->
               <!-- -->
               <!-- The two following lines are OK. -->

               <!-- <job name="initialisation" timeout="5" active="true"/> -->

               <job name="initialisation"/>

</configuration>



Complex element with text only (no attributes)



<?xml version="1.0"?>


<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="http://target.org"
           xmlns="http://target.org"
           elementFormDefault="qualified">


<!-- Define attributes -->
<!-- Note: all attributes are optional by default -->

     <xs:element name="configuration">
       <xs:complexType>
         <xs:simpleContent>
           <xs:extension base="xs:integer">
           </xs:extension>
         </xs:simpleContent>

       </xs:complexType>
     </xs:element>

</xs:schema>

<?xml version="1.0"?>

<configuration xmlns="http://target.org"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://target.org test2.xsd">


123

</configuration>



Complex element with text and attributes



<?xml version="1.0"?>


<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="http://target.org"
           xmlns="http://target.org"
           elementFormDefault="qualified">

<!-- Define attributes -->
<!-- Note: all attributes are optional by default -->

     <xs:element name="configuration">
       <xs:complexType>
         <xs:simpleContent>
           <xs:extension base="xs:integer">
             <xs:attribute name="country" type="xs:string" />
           </xs:extension>
         </xs:simpleContent>
       </xs:complexType>
     </xs:element>

</xs:schema>

<?xml version="1.0"?>

<configuration xmlns="http://target.org"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://target.org test2.xsd"
               country="france">


123

</configuration>



Complex element with mixed content: text and other elements



<?xml version="1.0"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="http://target.org"
           xmlns="http://target.org"
           elementFormDefault="qualified">

           <xs:element name="configuration" type="generic"/>

           <xs:complexType name="generic" mixed="true">

             <xs:sequence>
               <xs:element name="job" type="xs:string"/>
               <xs:element name="task" type="xs:string"/>
               <xs:element name="step" type="xs:string"/>
             </xs:sequence>

           </xs:complexType>

</xs:schema>

<?xml version="1.0"?>

<configuration xmlns="http://target.org"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://target.org test2.xsd">

   Configuration for the jobs

   <job>Name of the job</job>
   <task>Name of the task</task>
   <step>Name of the step</step>

</configuration>



Complex element with mixed content: text, other elements and attributes



<?xml version="1.0"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="http://target.org"
           xmlns="http://target.org"
           elementFormDefault="qualified">

           <xs:element name="configuration" type="generic"/>

           <xs:complexType name="generic" mixed="true">

             <xs:sequence>
               <xs:element name="job" type="xs:string"/>
               <xs:element name="task" type="xs:string"/>
               <xs:element name="step" type="xs:string"/>
             </xs:sequence>

             <!-- WARNING: Attributes MUST be declared at the end the <complexType> tag. -->

             <xs:attribute name="country" type="xs:string" />


           </xs:complexType>

</xs:schema>

<?xml version="1.0"?>

<configuration xmlns="http://target.org"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://target.org test2.xsd"
               country="france">

   Configuration for the jobs

   <job>Name of the job</job>
   <task>Name of the task</task>
   <step>Name of the step</step>

</configuration>



References and links



<?xml version="1.0"?>

<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<!-- This schema define the ** static ** configuration for a job. -->
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->





<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="http://target.org"
           xmlns="http://target.org"
           elementFormDefault="qualified">

        <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
        <!-- Define a short description -->
        <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

        <xs:simpleType name="short_description_type">
                <xs:restriction base="xs:string">
                        <xs:maxLength value="256" />
                </xs:restriction>
        </xs:simpleType>

        <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
        <!-- Define a job ID -->
        <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

        <xs:simpleType name="job_id_type">
                <xs:restriction base="xs:string">
                        <xs:pattern value="JOB_[A-Za-r0-9\-_]{1,32}" />
                </xs:restriction>
        </xs:simpleType>

        <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
        <!-- Define a file path -->
        <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

        <xs:simpleType name="path_type">
                <xs:restriction base="xs:string">
                        <xs:pattern value="[\.\-_a-zA-Z0-9]+(/[\.\-_a-zA-Z0-9]+)*" />
                </xs:restriction>
        </xs:simpleType>

        <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
        <!-- Define a job -->
        <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

        <xs:complexType name="job_type">

                <xs:sequence>

                        <xs:element name="SHORT_DESCRIPTION" type="short_description_type" />
                        <xs:element name="LONG_DESCRIPTION" type="xs:string" />

                </xs:sequence>

         <xs:attribute name="id" type="job_id_type" use="required" />
         <xs:attribute name="active" type="xs:boolean" use="required" />
         <xs:attribute name="first_task" type="xs:IDREF" use="required" />
         <xs:attribute name="crontab" type="xs:string" use="required" />

        </xs:complexType>

        <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
        <!-- Define a step configuration -->
        <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

        <xs:complexType name="step_type">

                <xs:sequence>

                        <xs:element name="SHORT_DESCRIPTION" type="short_description_type" />
                        <xs:element name="LONG_DESCRIPTION" type="xs:string" />
                        <xs:element name="PARAMS" type="xs:string" />

                </xs:sequence>

                <xs:attribute name="plugin" type="path_type" use="required" />
                <xs:attribute name="timeout" type="xs:integer" use="required" />

        </xs:complexType>

        <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
        <!-- Define a task configuration -->
        <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

        <xs:complexType name="task_type">

                <xs:sequence>

                        <xs:element name="SHORT_DESCRIPTION" type="short_description_type" />
                        <xs:element name="LONG_DESCRIPTION" type="xs:string" />
                        <xs:element name="STEP" type="step_type" minOccurs="1" maxOccurs="unbounded" />

                </xs:sequence>

                <xs:attribute name="id" type="xs:ID" use="required" />
                <xs:attribute name="on_success" type="xs:IDREF" use="required" />
                <xs:attribute name="on_failure" type="xs:IDREF" use="required" />

        </xs:complexType>

        <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
        <!-- Put all together -->
        <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

        <xs:element name="CONFIGURATION">
                <xs:complexType>
                        <xs:sequence>

                                <xs:element name="JOB" type="job_type" />
                                <xs:element name="TASK" type="task_type" minOccurs="1" maxOccurs="unbounded" />

                        </xs:sequence>
                </xs:complexType>

        </xs:element>

</xs:schema>

<?xml version="1.0"?>

<CONFIGURATION xmlns="http://target.org"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://target.org job_static.xsd">

        <JOB id = "JOB_1"
                        active = "true"
                        first_task = "task1"
                        crontab = "00 17 * * *">

                        <SHORT_DESCRIPTION>This job is use to send newsletters</SHORT_DESCRIPTION>
                        <LONG_DESCRIPTION>This is the long description for the job used to send newsletters</LONG_DESCRIPTION>
        </JOB>

        <TASK id="task1"
                        on_success="task2"
                        on_failure="task2">

                        <SHORT_DESCRIPTION>This is task 1</SHORT_DESCRIPTION>
                        <LONG_DESCRIPTION>This is the long description for task 1</LONG_DESCRIPTION>

                        <STEP plugin="check_disk.pl" timeout="10">

                                <SHORT_DESCRIPTION>Check the disk for errors.</SHORT_DESCRIPTION>
                                <LONG_DESCRIPTION>This step will check the disk for errors.</LONG_DESCRIPTION>
                                <PARAMS>disk=C</PARAMS>

                        </STEP>

                        <STEP plugin="txt2csv.pl" timeout="100">

                                <SHORT_DESCRIPTION>Concvert TXT into CSV.</SHORT_DESCRIPTION>
                                <LONG_DESCRIPTION>This step will take the text dump and convert it into CSV.</LONG_DESCRIPTION>
                                <PARAMS>file=export.txt</PARAMS>

                        </STEP>

        </TASK>

        <TASK id="task2"
                        on_success="task1"
                        on_failure="task1">

                        <SHORT_DESCRIPTION>This is task 2</SHORT_DESCRIPTION>
                        <LONG_DESCRIPTION>This is the long description for task 2</LONG_DESCRIPTION>

                        <STEP plugin="sendmail.pl" timeout="110">

                                <SHORT_DESCRIPTION>Send the status of the job.</SHORT_DESCRIPTION>
                                <LONG_DESCRIPTION>This step will send a message with the status (success, warning or error) of the job</LONG_DESCRIPTION>
                                <PARAMS>email=admin@domain.org</PARAMS>

                        </STEP>


        </TASK>


</CONFIGURATION>



Groups of elements



<?xml version="1.0"?>

<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<!-- This schema define the ** dymanic ** configuration for a job. -->
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->





<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="http://target.org"
           xmlns="http://target.org"
           elementFormDefault="qualified">


    <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
    <!-- Define a job ID -->
    <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

        <xs:simpleType name="job_id_type">
                <xs:restriction base="xs:string">
                        <xs:pattern value="JOB_[A-Za-r0-9\-_]{1,32}" />
                </xs:restriction>
        </xs:simpleType>

        <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
        <!-- Define the type of action for a job -->
        <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

        <xs:simpleType name="job_action_type">
                <xs:restriction base="xs:string">

                        <xs:enumeration value="abort" />
                        <xs:enumeration value="continue" />

                </xs:restriction>
        </xs:simpleType>

        <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
        <!-- Define the type of action for a task -->
        <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

        <xs:complexType name="task_action_type">
                <xs:choice>

                        <xs:element name="SKIP_ON_SUCCESS">
                                <xs:complexType>
                                </xs:complexType>
                        </xs:element>

                        <xs:element name="SKIP_ON_FAILURE">
                                <xs:complexType>
                                </xs:complexType>
                        </xs:element>

                        <xs:element name="ABORT">
                                <xs:complexType>
                                </xs:complexType>
                        </xs:element>

                        <xs:element name="SKIP_TO_TASK" type="xs:token" />

                </xs:choice>
        </xs:complexType>

        <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
        <!-- Define the type of action for a step -->
        <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

        <xs:complexType name="step_action_type">
                <xs:choice>

                        <xs:element name="SKIP">
                                <xs:complexType>
                                </xs:complexType>
                        </xs:element>

                        <xs:element name="ABORT">
                                <xs:complexType>
                                </xs:complexType>
                        </xs:element>

                        <xs:element name="SKIP_TO_STEP" type="xs:integer" />

                </xs:choice>
        </xs:complexType>

    <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
    <!-- Define an action for a job -->
    <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

    <xs:complexType name="job_type">

            <xs:sequence>

                    <xs:element name="DESCRIPTION" type="xs:string" />

            </xs:sequence>

            <xs:attribute name="id" type="job_id_type" use="required" />
            <xs:attribute name="action" type="job_action_type" use="required" />

    </xs:complexType>

    <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
    <!-- Define an action for a task -->
    <!-- Attributes "id" can ** NOT ** be duplicated! -->
    <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

    <xs:complexType name="task_type">

            <xs:sequence>

                    <xs:element name="DESCRIPTION" type="xs:string" />
                    <xs:element name="ACTION" type="task_action_type" />

            </xs:sequence>

            <xs:attribute name="id" type="xs:ID" use="required" />

    </xs:complexType>

    <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
    <!-- Define an action for a step -->
    <!-- WARNING! Attributes "task" can be duplicated! This means that -->
    <!-- you can abort a task and still modify steps within this task !!! -->
    <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

    <xs:complexType name="step_type">

            <xs:sequence>

                    <xs:element name="DESCRIPTION" type="xs:string" />
                    <xs:element name="ACTION" type="step_action_type" />

            </xs:sequence>

            <xs:attribute name="task" type="xs:token" use="required" />
            <xs:attribute name="rank" type="xs:integer" use="required" />

    </xs:complexType>

    <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
    <!-- Tasks and steps -->
    <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

    
    <xs:group name="tasks_and_steps">
             <xs:sequence>
                        <xs:element name="TASK" type="task_type" minOccurs="0" maxOccurs="unbounded" />
                        <xs:element name="STEP" type="step_type" minOccurs="0" maxOccurs="unbounded" />
             </xs:sequence>
    </xs:group>
    


    <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
    <!-- Put all together -->
    <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

        <xs:element name="CONFIGURATION">
                <xs:complexType>
                        <xs:choice>

                                <xs:element name="JOB" type="job_type" minOccurs="0" maxOccurs="1" />
                                <xs:group ref="tasks_and_steps" />

                        </xs:choice>
                </xs:complexType>
        </xs:element>


</xs:schema>

<?xml version="1.0"?>

<CONFIGURATION xmlns="http://target.org"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://target.org job_dynamic.xsd">


        <TASK id="task1">

                        <DESCRIPTION>A big problem forces us to abort this task.</DESCRIPTION>
                        <ACTION>
                                <SKIP_TO_TASK>task2</SKIP_TO_TASK>
                        </ACTION>
        </TASK>

        <TASK id="task2">

                        <DESCRIPTION>A big problem forces us to abort this task.</DESCRIPTION>
                        <ACTION>
                                <SKIP_TO_TASK>task1</SKIP_TO_TASK>
                        </ACTION>
        </TASK>


</CONFIGURATION>



Restrictions for Datatypes


Constraint Description
enumeration Defines a list of acceptable values
fractionDigits Specifies the maximum number of decimal places allowed. Must be equal to or greater than zero
length Specifies the exact number of characters or list items allowed. Must be equal to or greater than zero
maxExclusive Specifies the upper bounds for numeric values (the value must be less than this value)
maxInclusive Specifies the upper bounds for numeric values (the value must be less than or equal to this value)
maxLength Specifies the maximum number of characters or list items allowed. Must be equal to or greater than zero
minExclusive Specifies the lower bounds for numeric values (the value must be greater than this value)
minInclusive Specifies the lower bounds for numeric values (the value must be greater than or equal to this value)
minLength Specifies the minimum number of characters or list items allowed. Must be equal to or greater than zero
pattern Defines the exact sequence of characters that are acceptable
totalDigits Specifies the exact number of digits allowed. Must be greater than zero
whiteSpace Specifies how white space (line feeds, tabs, spaces, and carriage returns) are handled