开发者

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 namespac开发者_Python百科e '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...

  • Are spaces not allowed in schema names?
  • Does the schemaLoaction need to match the targetNamespace?
  • If so, why!?


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


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:

  • http://www.somesite.com/schema/2.0+SomeObject.xsd or
  • http://www.somesite.com/schema/2.0%20SomeObject.xsd
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜