Justin
Justin

Reputation: 86729

Failure validating Xml: The namespace 'X' provided differs from the schema's targetNamespace 'Y'

I'm getting the following error while validating an xml document while using IXMLDOMDocument2 (C++):

The namespace 'http://www.somesite.com/schema/2.0' provided differs from the schema's targetNamespace 'http://www.somesite.com/schema/2.0/SomeObject' .

The Xml I'm trying to validate is:

<id:envelope xmlns:id="http://www.somesite.com/schema/2.0/SomeObject" 
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
             xsi:schemaLocation="http://www.somesite.com/schema/2.0 SomeObject.xsd">
    <!-- content -->
</id:envelope>

Now I can see that it looks like the xsi:schemaLocation tag has been mangled a bit by the space ("http://www.somesite.com/schema/2.0 SomeObject.xsd" seems to be getting interpreted as "http://www.somesite.com/schema/2.0"), but I still cant quite understand whats going on as this appears to indicate that the schemaLoaction needs to exactly match the xmlns specified...

Upvotes: 0

Views: 2042

Answers (2)

mmmmmm
mmmmmm

Reputation: 32671

schemaLocation contais a way of mapping a schema to a place where the schema representation can be found

In this case schemaLocation should contain a pair of strings

The schema name - exactly matching the namespace id given

Where it is found in this case a relative file SomeObject.xsd

The definitions are in the W3C schema spec see example in section 4.3.2

So a corrected version might be xsi:schemaLocation="http://www.somesite.com/schema/2.0/SomeObject http://www.somesite.com/schema/2.0SomeObject.xsd

Upvotes: 2

jarnbjo
jarnbjo

Reputation: 34313

I don't know the actual parser you're using, but since the schema location is a URL and URLs are not allowed to contain spaces, perhaps the parser is simply spitting out an incorrect error message. Try proper URL-encoding of the schmea location and see if that helps:

Upvotes: 0

Related Questions