I want an XML file split up with several includes, using XInclude. This method I prefere above others, because the included XML files can be standalone to be validated files on their own.
I have the following sample schema (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>
I made part a global element so I could start an new xml element with the root element "part". Now my xml files look like:
The main file (mybook.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>
And my include file (part2.xml):
<?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>
Within XmlSpy, now I can successfully validate part2.xml. However when validating mybook.xml, I got the following error:
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}'.
Because I'm failry new to XML I cannot see (but tried several things) what needs to be done to have both XML files validate successfully against the mybook.xsd.
Can anyone help me? Thanks in advance