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。
誰でも手伝ってもらえますか?事前に感謝します
おそらく、質問に答えが得られない場合は、http://stackoverflow.com/questions/1098116/xinclude-schema-namespace-problemを参照してください。 – Istao
はい、私はすでにその質問を調べましたが、何をしようとしても、検証中にエラーが発生します。私は、XIncludeメソッドの利点の1つは、2つのXMLファイルの検証に成功する可能性があると考えていたので、これを実現する方法があるはずです。 – eiri