2016-04-19 12 views
0

xmlスキーマとmy xmlドキュメントの両方が有効で整形式です。しかし、正しい参照にはまだ問題があります。私はいくつかの同様の質問を見上げたが、私は私の問題を解決することはできません。xmlスキーマ参照の問題

XMLスキーマのはじまり:

<?xml version="1.0" encoding="UTF-8"?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
targetNamespace="http://www.w3schools.com" 
xmlns="http://www.w3schools.com"> 


<xs:element name="catalog"/> 

XMLスキーマ例:

<xs:element name="Qstr"> 
<xs:complexType> 
    <xs:sequence> 
     <xs:element name="text" type="xs:string"/> 
     <xs:element name="a" type="xs:string"/> 
     <xs:element name="b" type="xs:string"/> 
     <xs:element name="c" type="xs:string"/> 
     <xs:element name="d" type="xs:string"/> 
    </xs:sequence> 
</xs:complexType> 

、XML文書の冒頭:

<?xml version="1.0" encoding="UTF-8"?> 



<catalog xmlns="http://www.w3schools.com" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.w3schools.com file:///home/n/workspace/webprog1/WebContent/schema.xml"> 

<Qstr> 
    <text>random question?</text> 
    <a>asdfasd</a> 
    <b>ertwetrewt</b> 
    <c>ghkghk</c> 
    <d>xcvbxcbbx</d> 
</Qstr> 

エラーメッセージ:

Invalid content was found starting with element '{"http://www.w3schools.com":text}'. One of '{text}' is expected. 
+0

は、「テキスト」について語ったスキーマの一部を表示します。 – choroba

答えて

1

のelementFormDefaultのデフォルト値は、修飾されていないです。 <catalog>の既定の名前空間を使用しているため、すべての子要素も同じ名前空間になります(名前空間が必要ではありません)。

など。詳細はhereを参照してください。

あなたのようなものに変更した場合、それはおそらく(フルXSDを貼り付けていなかった)動作します:

<myns:catalog xmlns:myns="http://www.w3schools.com" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.w3schools.com file:///home/n/workspace/webprog1/WebContent/schema.xml"> 

<myns:Qstr> 
    <text>random question?</text> 
    <a>asdfasd</a> 
    <b>ertwetrewt</b> 
    <c>ghkghk</c> 
    <d>xcvbxcbbx</d> 
</myns:Qstr> 
+0

返答いただきありがとうございます。elementFormDefaultを "qualified"に設定しましたが、今はエラーが発生していません。私の実際の問題(xmlファイルをhtmlに変換する)はまだ解決されていませんが、もう別の質問でそれについて尋ねました。 –

+0

OK、それが助けられたら、答えを受け入れるか、少なくとも投票してください。ありがとう。 –