XInclude Schema / Namespace Validation?

I am trying to use XML Includes to manage a large XML structure that should be used by both people and machines.

But I am experiencing a lot of problems when trying to create XML files that can be validated against an existing schema. Here's a simplified example of what I'm trying to do.

My file "main.xml" is not checked.

<?xml version="1.0" encoding="UTF-8"?>
<!-- Main.xml - This fails to validate. -->
<ns1:main xsi:schemaLocation="http://www.example.com/main main.xsd"
          xmlns:ns1="http://www.example.com/main"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:xi="http://www.w3.org/2001/XInclude">

    <name>String</name>
    <xi:include href="child.xml"/> <!-- What I'm trying to do. -->

</ns1:main>

The child.xml file checks as a stand-alone file.

<?xml version="1.0" encoding="UTF-8"?>
<!-- Child.xml - This validates fine, as a standalone file. -->
<ns1:child xsi:schemaLocation="http://www.example.com/main main.xsd"
           xmlns:ns1="http://www.example.com/main"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <name>String</name>
    <age>String</age>

 </ns1:child>

Here is my diagram:

 <?xml version="1.0" encoding="UTF-8"?>
 <!-- Main.xsd - My Simplified Schema -->
 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
            xmlns:ns1="http://www.example.com/main"
            targetNamespace="http://www.example.com/main">

    <!-- Main Element (References Child) -->
    <xs:element name="main">
         <xs:complexType>
             <xs:sequence>
                 <xs:element name="name" type="xs:string"/>
                 <xs:element ref="ns1:child"/>
             </xs:sequence>
         </xs:complexType>
    </xs:element>

    <!-- Child Element -->
    <xs:element name="child">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="name" type="xs:string"/>
                <xs:element name="age" type="xs:string"/>
            </xs:sequence>
        </xs:complexType>
     </xs:element>

</xs:schema>

My problems are almost explicitly related to namespaces, but I don't understand how to fix my problem.

+3
source share
4 answers

As the scaffman already pointed out, XML Schema and XInclude are incompatible.

xmllint :

main.xml:9: element include: Schemas validity error : Element  '{http://www.w3.org/2001/XInclude}include': This element is not expected. Expected is ( {http://www.example.com/main}child ).
main.xml fails to validate

W3C: "XInclude , XML-. , , ".

, XML , XIncludes .

: xmllint -xinclude main.xml.

+5

, XML Schema XInclude . XML , .

, , .

P.S. , , . ?

+2

grantwparks - XInclude XML Schema . . -, XInclude .

, , , xml.com, :

XInclude , , XSL XML-. : . XInclusion - XML. , , .

, . , , . xi: include, xi: include , . xi: , . , , ,

, , -, , XML xi: include ( , OP). , XML Eclipse " XML " XML → XML → ( RSA 8.5), , xi: include before .

Andy

+2

, XInclude ; , . , "include" , "" . XML , ...

0

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


All Articles