2010-12-18 5 views
3

XIncludeを使用して、複数のインクルードで分割されたXMLファイルが必要です。この方法は私が他の人よりも優先します。なぜなら、インクルードされたXMLファイルをスタンドアロンで検証することができるからです。X検証の問題を含む

私は、次のサンプル・スキーマ(mybook.xsd)を持っている:


<?xml version="1.0" encoding="UTF-8"?> 
<xs:schema 
xmlns:xs="http://www.w3.org/2001/XMLSchema" 
elementFormDefault="qualified" 
attributeFormDefault="unqualified"> 
<xs:import 
    namespace="http://www.w3.org/XML/1998/namespace" 
    schemaLocation="http://www.w3.org/2001/xml.xsd"/> 
<xs:element name="mybook"> 
    <xs:annotation> 
    <xs:documentation>Comment describing your root element</xs:documentation> 
    </xs:annotation> 
    <xs:complexType> 
    <xs:sequence> 
    <xs:element name="toc"> 
    <xs:complexType> 
     <xs:attributeGroup ref="xml:specialAttrs"/> 
    </xs:complexType> 
    </xs:element> 
    <xs:element ref="part" maxOccurs="unbounded"/> 
    <xs:element name="index"> 
    <xs:complexType> 
     <xs:attributeGroup ref="xml:specialAttrs"/> 
    </xs:complexType> 
    </xs:element> 
    </xs:sequence> 
    </xs:complexType> 
</xs:element> 
<xs:element name="part"> 
    <xs:complexType> 
    <xs:sequence> 
    <xs:element name="chapter" maxOccurs="unbounded"> 
    <xs:complexType> 
     <xs:sequence> 
     <xs:element name="page" maxOccurs="unbounded"> 
     <xs:complexType> 
     <xs:simpleContent> 
      <xs:extension base="xs:string"> 
      <xs:attributeGroup ref="xml:specialAttrs"/> 
      </xs:extension> 
     </xs:simpleContent> 
     </xs:complexType> 
     </xs:element> 
     </xs:sequence> 
     <xs:attributeGroup ref="xml:specialAttrs"/> 
    </xs:complexType> 
    </xs:element> 
    </xs:sequence> 
    <xs:attributeGroup ref="xml:specialAttrs"/> 
    <xs:attribute name="chaptername" use="required"/> 
    </xs:complexType> 
</xs:element> 
</xs:schema> 

私はルート要素「一部」との新しいXML要素を開始することができますので、私は一部にグローバル要素を作りました。

メインファイル(mybook.xml):今私のxmlファイルは次のようになり


<?xml version="1.0" encoding="UTF-8"?> 
<mybook 
xsi:noNamespaceSchemaLocation="mybook.xsd" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:xi="http://www.w3.org/2001/XInclude" > 
<toc/> 
<part chaptername="Chapter 1" > 
    <chapter> 
    <page>String</page> 
    <page>String</page> 
    </chapter> 
    <chapter> 
    <page>String</page> 
    <page>String</page> 
    </chapter> 
</part> 
    <xi:include href="part2.xml"/> 
<index/> 
</mybook> 

そして、私は、ファイル(part2.xml)が含まれます:XMLSpy以内


<?xml version="1.0" encoding="UTF-8"?> 
<part chaptername="Chapter 2" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:noNamespaceSchemaLocation="mybook.xsd" > 
<chapter> 
    <page>String</page> 
    <page>String</page> 
</chapter> 
<chapter> 
    <page>String</page> 
    <page>String</page> 
</chapter> 
</part> 

、今私ができるのpart2.xmlの検証に成功しました。 mybook.xmlを検証するときにしかし、私は次のエラーを得た:

 
File mybook.xml is not valid. 
File part2.xml is not valid. 
    The 'noNamespaceSchemaLocation' attribute references a schema whose target namespace was already used for validation. 
    Error location: part 
    Details 
    The 'noNamespaceSchemaLocation' attribute references a schema whose target namespace was already used for validation. 
    cvc-elt.5.2.1: The element is not valid with respect to the actual type definition '{anonymous}'. 

私は私が見る(ただし、いくつかのことを試してみました)することはできませんXMLへfailry新たなんだので、両方のXMLファイルはに対して首尾よく検証していするために何をすべきかmybook.xsd。

誰でも手伝ってもらえますか?事前に感謝します

+0

おそらく、質問に答えが得られない場合は、http://stackoverflow.com/questions/1098116/xinclude-schema-namespace-problemを参照してください。 – Istao

+0

はい、私はすでにその質問を調べましたが、何をしようとしても、検証中にエラーが発生します。私は、XIncludeメソッドの利点の1つは、2つのXMLファイルの検証に成功する可能性があると考えていたので、これを実現する方法があるはずです。 – eiri

答えて

2

あなたはnoNamespaceSchemaLocationの使用に関する制限に対して実行しています。基本的に、これはXSDバリデータのスキーマの検索方法のヒントとして使用できます。多かれ少なかれ、この属性を複数回表示させることはできません。 thisを参照してください。

最初のnoNamespaceSchemaLocationが発生し、 "mybook"要素を検証できるように名前空間スキーマを見つける方法をバリデータに伝えます。後で、 "part"要素になると、別のnoNamespaceSchemaLocationが見つかりますが、それはすでに検証されている "mybook"要素の何らかの他の定義をもたらす場合、それは何ですか?そのような理由から、仕様ではこのようなことが許されないため、あなたが指摘したエラーが発生します。

noNamespaceSchemaLocationを使用するのではなく、バリデーターにスキーマ文書の検索方法を伝えるために、他の方法に頼る必要があるようです。