Shammer's Philosophy

My private adversaria

Schema in ***.xsd has a different target namespace from the one specified in the instance document

内容以前にカテゴリをJavaにしているけれど・・・XMLにすべきか。
う〜ん、まあJavaで解析しているからJavaでよしとしよう。

XML Schema 宣言部で下記のようになっている場合、

<org:sample
  xmlns:org="http://www.sample.com/myoriginal"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.sample.com/myoriginal sample.xsd">

接頭辞「org」は、名前空間http://www.sample.com/myoriginal”を置き換えるものであり、
xsi:schemaLocationで定義される左側のURLと一致していなければならない。このURLが異なっていると、

[Error] valid-schema-sample.xml:5:42:General Schema Error: Schema in sample.xsd has a different target namespace from the one specified in the instance document :sample.

というエラーが出てしまう。

このxsi:schemaLocationの解釈方法については仕様レベルでは決まっていないらしい。
あくまでも、XML Parserの実装依存という話になるようだ。XML Schema Part 0: Primer Second Editionには、

the attribute xsi:schemaLocation provides hints from the author to a processor regarding the location of schema documents.

とある。解析手法やエラーメッセージがどのようになるかは、Parser依存か。
今回は、Xercesを使ってメッセージを確認したけれども、別のParserを使うと別のメッセージになると考えるのが自然だな。
自分の書いたXMLがうまく解析されない場合、Parserのバグかとか思いたくなるが、
それを立証するにはXML Schemaの勧告をすべて把握しておかなければならないな。
そうでなければ、Parserのバグだという立証ができないことになる。
どのように書くべきか、というのをいろいろいじって試してみたいが・・・
その前に、すでに確認できているエラーを潰していかないとなぁ。