> The schema location worked when I set it as the value of the property
> "http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation";,



If it worked, then the schema must have been originally defined with no targetNamespace attribute, so you must have changed the schema. Then you say if you were setting the property in the instance document, you would give a different URI for the location. I'm confused. Maybe you have your examples mixed up.


First off, did you try to specify the schema location in the document? We know unequivocally that the URI in the document must be relative to the document, per your last example. Does that work? Trying that will at least produce an error message that differentiates between not being able to find the schema and not finding the element decl in the schema.

Bob Foster

[EMAIL PROTECTED] wrote:

Hi,

Michael, thankyou very much for your help. I was indeed missing the namespace part of the property. This has fixed one error, but the second remains:

Illegal XML: cvc-elt.1: Cannot find the declaration of element 'Root'.


Again, it seems to me that either the schema can't be found or the Root element can't be matched against the one defined in the schema.
My schema is now:


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


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


My instance document begins:

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


And my code reads:
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);
}


Where schemaLocation is "http://www.mynamespace.com conf/BDM-FDDNUServletRequest.xsd"

The schema location worked when I set it as the value of the property "http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation";, so presumably the parser's still finding the schema.

If I was specifiying a schema within an instance document I'd use something like this:

<Root  xmlns="http://www.mynamespace.com";
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
        xsi:schemaLocation="http://www.mynamespace.com FormsSchema.xsd">

Does setting the "external-schemaLocation" property on Xerces avoid the need for me to have to set the second of these three properties?

What final connecting element am I still missing?


Thanks again for your time,

John





Michael Glavassevich <[EMAIL PROTECTED]> wrote on 14/01/2005 09:45:07 AM:

> Hello John,
>
> The value of the external-schemaLocation property is a list of pairs of
> URIs (just like the xsi:schemaLocation attribute [1]), where the first of
> each pair is a target namespace and the second of each pair is a schema
> location hint. Did you specify the target namespace before the location
> "conf/BDM-FDDNUServletRequest.xsd"? If not, that probably explains why you
> get the error.
>
> Thanks.
>
> [1] http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/#schema-loc
>
> [EMAIL PROTECTED] wrote on 01/12/2005 01:15:59 AM:
>
> >
> > 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
> >
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: [EMAIL PROTECTED]
> E-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to