xmlxsdxinclude

simple use of xinclude in xml docs


I found a few Q's relating to xinclude, but none that specifically answered my very basic question about how to include external docs

Here are a couple of xml docs that I would like to ref each other:

<?xml version="1.0" encoding="UTF-8"?>
<t:person xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://test test-schema.xsd"
    xmlns:t="http://test">

    <t:first-name>Wilma</t:first-name>
    <t:last-name>Flintstone</t:last-name>
    <t:spouse>
        <xi:include xmlns:xi="http://www.w3.org/TR/xinclude" href="fred.xml"/>
    </t:spouse>

</t:person>

<?xml version="1.0" encoding="UTF-8"?>
<t:person xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://test test-schema.xsd"
 xmlns:t="http://test">
    <t:first-name>Fred</t:first-name>
    <t:last-name>Flintstone</t:last-name>
    <t:spouse>
        <xi:include xmlns:xi="http://www.w3.org/TR/xinclude" href="wilma.xml"/>
    </t:spouse>
</t:person>

and the schema:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://test"
    targetNamespace="http://test" elementFormDefault="qualified"> 

<xs:element name="person" type="personType"/>

<xs:complexType name="personType">
    <xs:sequence>
        <xs:element name="first-name" type="xs:string"/>
        <xs:element name="last-name" type="xs:string"/>
        <xs:element name="spouse" type="personType"/>
    </xs:sequence>
</xs:complexType>

</xs:schema>

the xi:include element is coming up as invalid. I've been searching around, and can't find a simple example like this. The xi:include simply a stand-in for the element that is supposed to be there, correct?

thanks, bp


Solution

  • Someone who wants to perform both validation and XInclude processing may wish to perform XInclude first, then validate, or to validate first, then perform XInclude, or validate first, then perform XInclude processing, then validate again. In the current state of mind-reading technology, software cannot tell which of these is desired without help from the human. You know what order you want things to happen in, but have you told your software? From your description, it sounds as if your processor defaults to validate-first, then do XInclude; if you want a non-default processing sequence, you'll have to tell your processor. How you do that is processor-dependent; read the documentation.