Validating XML file with RelaxNG

135 Views Asked by At

Having two same files with only difference using interleave in on of them:

RelaxNG schema:

<?xml version="1.0" encoding="UTF-8"?>
 <grammar 
 xmlns="http://relaxng.org/ns/structure/1.0" 
 datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
 <start>
     <element>
         <name>blog</name>
         <element>
             <name>lastupdate</name>
             <data type="dateTime"/>
         </element>
         <optional>
              <element>
              <name>articles</name>
              <oneOrMore>
                  <element>
                     <name>article</name>
                       <interleave>
                         <element>
                             <name>unique_id</name>
                             <data type="string"/>
                         </element>
                         <element>
                             <name>title</name>
                             <data type="string"/>
                         </element>
                         <element>
                             <name>description</name>
                             <data type="string"/>
                         </element>
                         <optional>
                             <element>
                                 <name>tags</name>
                                 <data type="string"/>
                             </element>
                          </optional>
                      </interleave>
                   </element>
              </oneOrMore>
          </element>
      </optional>
  </element>
  </start>
</grammar>

The XML file:

<?xml version="1.0" encoding="UTF-8"?>
 <blog>
    <last_update>2016-01-25T10:45:00Z</last_update>
    <articles>
       <article>
            <tile>First article</tile>
            <unique_id>1112313111</unique_id>
            <description>Testing the first article of the blog</description>
            <tags>
                <tag>News</tag>
            </tags>
        </article>
    </articles>
 </blog>

When failing the validation in case of interleaving the error messages are wrong. For example giving false name to the required element title:

tile instead of title

the error message is returning the previous required element despite the fact it is valid!

'Expecting an element unique_id, got nothing, line 5'

On the other side without using interleave every error message is specific and correct.

Using python, etree.parse to parse the .rng file and the RelaxNG class to validate.

I cannot find out why is this happening.

0

There are 0 best solutions below