I'm trying to use namespaces on a xml file composed by more files.
XML Schema
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema
version="1.0"
attributeFormDefault="unqualified"
elementFormDefault="qualified"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="urn:mynamespace"
targetNamespace="urn:mynamespace">
<xsd:element name="main_element" type="typeMainElement" />
<xsd:complexType name="typeMainElement">
<xsd:sequence>
<xsd:element name="inner_element" type="typeInnerElement" />
</xsd:sequence>
<xsd:attribute name="test_attribute" type="xsd:string" use="required" />
</xsd:complexType>
<xsd:complexType name="typeInnerElement">
<xsd:sequence>
<xsd:element name="description" type="xsd:string" minOccurs="0" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
Main XML
<main_element test_attribute="value"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns="urn:mynamespace">
<inner_element>
<description>Test</description>
</inner_element>
</main_element>
Validating the XML with the XML Schema works perfectly.
But if I try to outsource some part of the XML, relying on XInclude
then nothing works anymore.
Splitted XML
<main_element test_attribute="value"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns="urn:mynamespace">
<xi:include href="simple_part.xml" />
</main_element>
Included XML
<inner_element>
<description>Test</description>
</inner_element>
Trying to validate the Splitted XML returns the error:
simple_part.xml:1: element inner_element: Schemas validity error : Element 'inner_element': This element is not expected. Expected is ( {urn:mynamespace}inner_element ).
simple_main_element.xml fails to validate
It seems that when including I loose the namespace inheriting, so the included content doesn't have a namespace anymore.