Re: problem referencing attributes from imported namespace

Yes, obviously you were right. Thank you for your answer.
Now I only have this error:

org.xml.sax.SAXParseException: cvc-complex-type.3.2.2: Attribute 'encodingStyle' is not allowed to appear in element 'SOAP:Envelope'.

And my xml document root looks as follows:

<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope" SOAP:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">

I've checked the envelope schema and it seems the attribute declaration is global.

Another thing I haven't quite understood (but that may be because I'm a newbie to schemas and xml validation and I haven't had the chance to study properly) is how the validating parser finds the schemas I use in my xml and xsd documents. I use Xerces 2.4.0, and my xml document doesn't have a link to an external schema document, so I have to set that in my code:

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();		
factory.setNamespaceAware(true);
factory.setValidating(true);
factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage","http://www.w3.org/2001/XMLSchema");

//String[] schemas = new String[]{schema, "envelopeSchema.xsd", "xmldsigSchema.xsd"};
factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", schema);

where schema is the String containing the path to my xsd, which the application finds. But to have it work I have to use the schemaLocation attribute in my xsd import elements to set the path of the imported schema files (which I have saved locally from http://schemas.xmlsoap.org/soap/envelope and http://www.w3.org/2000/09/xmldsig#: did I really need to do that?).
From the w3c schema specification, in the section about the import element:

"The ·actual value· of the schemaLocation, if present, gives a hint as to where a serialization of a ·schema document· with declarations and definitions for that namespace (or none) may be found. When no schemaLocation [attribute] is present, the schema author is leaving the identification of that schema to the instance, application or user, via the mechanisms described below..."

That's exactly what I wanted to do: leave the identification of that schema to the application. And I tried to do that using the following code:

String[] schemas = new String[]{schema, "envelopeSchema.xsd", "xmldsigSchema.xsd"};
factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", schemas);

But it just doesn't seem to work, because, after removing the schemaLocation attribute, I get the same error whether I set the above attribute with my custom schema or with the array of schemas, and the error is:

org.xml.sax.SAXParseException: src-resolve: Cannot resolve the name 'soap:mustUnderstand' to a(n) attribute declaration component.

So it seems the parser has an internal representation of the schemas I downloaded (for instance, that of the soap envelope), as I expected, but slightly different from the latest one. Is my assumption right?
Anyway, is there a way to do that programmatically (tell the parser which file to use to resolve the import statements)?
Thanks,
MJ




> I think that the problem is that the namespaces don't quite match.
> You've declared the SOAP namespace as:
> 
>   http://schemas.xmlsoap.org/soap/envelope
> 
> but you're importing the namespace:
> 
>   http://schemas.xmlsoap.org/soap/envelope/
>                                           ^
> remove the extra slash -------------------| and it should work.
>   
> Cheers,
> 
> Jeni
> 
> ---
> Jeni Tennison
> http://www.jenitennison.com/
> 
> 

Received on Thursday, 24 July 2003 12:35:14 UTC