XML Schema validation in eXist

Testing Sebastian Bossung's contribution

J.M. Vanel - Send your comments - My home page - Last update: 



2004-08-07


I added a targetNamespace to addressBook.xsd . It validates in command line with Xerces 2.6.2 (HOWTO to validate against an external Schema not assigned in the XML instance). But with eXist I still have this error :

Error validating: 
Error: (2, 61): cvc-elt.1: Cannot find the declaration of element 'addressBook'.

The commands executed in an empty database are :

put       test/addressBook.xml
putschema test/addressBook.xsd
validate addressBook.xml
After several trials, we see that the same schema has been stored several times:
ls -l system/schema
-rwur-ur-- admin dba .index
-rwur-ur-- admin dba 1091861545041
-rwur-ur-- admin dba 1091862120128
-rwur-ur-- admin dba 1091862239719
-rwur-ur-- admin dba 1091862312764
However the document system/schema/.index is still quite empty:
<?xml version="1.0" encoding="ISO-8859-1"?>
<schema-index/>
I suspect that the way the target namespace is set in the XSD was not implemented.
 
I try without a default namespace :
samples/addressBook-no-default-ns.xsd
Same symptoms :-((((((

I have in the test XSD until now:
   elementFormDefault="qualified"
attributeFormDefault="unqualified"
Maybe I have to test other settings ... But first I debug to see what is happening. I also changed the importSchema() function so that it doesn't block the GUI when something is wrong.I also updated my page How to test eXist , showing how to debug  the eXist GUI.

AAAAAAAAAAAAAAAAAAAAAhhhhhhhhhhhhhhhh I saw something ! In class GenericSchemaService :

    private void addToIndex(String targetNamespace, String filename) throws XMLDBException {
        XMLResource index = getIndexResource();
        Node rootNode = index.getContentAsDOM();
        Document doc = rootNode.getOwnerDocument();
        Element schemaNode = doc.createElement("schema");
        Attr targetNamespaceAttr = doc.createAttribute("targetNamespace");
        targetNamespaceAttr.setNodeValue(targetNamespace);

the call in bold doesn't really set the value ... This is in class org.exist.dom.AttrImpl, but by inheritance the implementation is from NodeImpl, and does nothing !!!??? . There is a function setNode() in class org.exist.dom.AttrImpl; I try that: it still doesn't work. I replace 6 lines with these simpler lines:
		schemaNode.setAttribute("targetNamespace", targetNamespace);
schemaNode.setAttribute("resourceName", filename);
it still doesn't work! There should be a new element in the document system/schema/.index :
<schema targetNamespace="http://jmvanel.free.fr/xsd/addressBook" 
resourceName="123543897" />
But the ressource isn't changed at all. As if the DOM interface for modifying a resource doesn't work ?
I have to pass the general JUnit tests: all is fine!.

I will now write a test of the DOM interface when modifying a resource.
OK, done:
org.exist.xmldb.test.DOMTestJUnit

>>>>>>>>>>>>>>>>>>>>>>>> to be continued ..............

Test files

addressBook.xsd :

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://jmvanel.free.fr/xsd/addressBook"
    xmlns="http://jmvanel.free.fr/xsd/addressBook"
           elementFormDefault="qualified"
           attributeFormDefault="unqualified"
>

  <xsd:complexType name="record">
     <xsd:sequence>
        <xsd:element name="cname" type="xsd:string"/>
        <xsd:element name="email" type="xsd:string"/>
     </xsd:sequence>
  </xsd:complexType>

  <xsd:element name="addressBook">
     <xsd:complexType>
        <xsd:sequence>
        <xsd:element name="owner" type="record"/>
        <xsd:element name="person" type="record"
                       minOccurs="0" maxOccurs="unbounded"/>
        </xsd:sequence>            </xsd:complexType>
  </xsd:element>

</xsd:schema>

----------------

addressBook.xml :

<?xml version="1.0"?>
<addressBook xmlns="http://jmvanel.free.fr/xsd/addressBook">
     <owner>
        <cname>John Punin</cname>
        <email>puninj@cs.rpi.edu</email>
     </owner>
     <person>
        <cname>Harrison Ford</cname>
        <email>hford@famous.org</email>
     </person>
     <person>
        <cname>Julia Roberts</cname>
        <email>jr@pw.com</email>
     </person>
</addressBook>


Links

How to test eXist

Exist-open@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/exist-open