Hi,

Apologies if this is an FAQ, I've read a thread in the archive that seems to match my problem but I can't get the fix to work.  The thread was entitled "Validation fails with targetNamespace == default" and lives at:  http://mail-archives.apache.org/eyebrowse/ReadMsg?listId=85&msgNo=2861

I'm attempting to add a namespace to a schema and instance documents that I'm validating on a servlet.  

I have something like the following as my schema:

<xs:schema  xmlns:xs="http://www.w3.org/2001/XMLSchema"
                        xmlns:xsi="http://www.w3.org/2001/XMLSchema-Instance"        
                        version="0.9"
                        targetNamespace="http://www.mynamespace.com/"
                        xmlns="http://www.mynamespace.com/"
                        elementFormDefault="qualified">

  <xs:element name="Root">
    <xs:complexType>
          <xs:choice>
                blah blah blah..



I have an instance document like this:

<Root xmlns="http://www.mynamespace.com/"><blah blah blah..


And I'm attempting to set up validation using the following code (and Xerces 2.6.0) :

            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();            
            if(schemaLocation != null) {
                factory.setNamespaceAware(true);
                factory.setValidating(true);
                factory.setAttribute("http://apache.org/xml/features/validation/schema", Boolean.TRUE);
                factory.setAttribute("http://apache.org/xml/properties/dom/document-class-name", "org.apache.xerces.dom.PSVIDocumentImpl");
                factory.setAttribute("http://apache.org/xml/properties/schema/external-schemaLocation", schemaLocation);
            }


I think I've done everything in the checklist mentioned in the archived thread:

a) Defined targetNamespace and elementFormDefault on my schema.
b) Use namespace defaulting for unprefixed elements in my instance document.
c) Tell the parser the location of the schema (say, "conf/BDM-FDDNUServletRequest.xsd" ).


However, validation is failing with the following error:

Failed validation with the following errors:
Illegal XML: http://www.w3.org/TR/xml-schema-1#SchemaLocation?/usr/local/jakarta-tomcat-5.0.18/webapps/BDM-OsirisServer/conf/BDM-FDDNUServerRequest.xsd
Illegal XML: cvc-elt.1: Cannot find the declaration of element 'Root'.


Does this mean that it either can't find the schema because the namespace it's using is "http://www.w3.org/TR/xml-schema-1#SchemaLocation" instead of the default one mentioned in the instance document?

Or does it mean that it's found the schema and I've missed something in my instance document?

Any hints, pointers or tips as how to get this to validate would be gratefully appreciated.

Thanks for your time,

John Greenhow

 

Reply via email to