XInclude validation problem

I want the XML file to be broken into several inclusions using XInclude. I prefer this method above others, because the included XML files can be stand-alone for checking 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 the global element part, so I could start a new xml element with the root element "part". Now my xml files look like this:

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>

In XmlSpy, I can now successfully verify part2.xml. However, while checking mybook.xml, I received 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}'.

XML, ( ), , XML mybook.xsd.

- ?

+3
1

noNamespaceSchemaLocation. , XSD , . . this.

, noNamespaceSchemaLocation , , "mybook" . , "part", noNamespaceSchemaLocation, , , "mybook", , ? ​​, , , .

, - , , , noNamespaceSchemaLocation.

+2

Source: https://habr.com/ru/post/1781003/


All Articles