xarx
xarx

Reputation: 657

xsd import from xsd include

I'm having the following "imp.xsd":

<xsd:schema targetNamespace="http://imported"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:element name="Imported" type="xsd:string"/>
</xsd:schema>

imported from "incl.xsd":

<xsd:schema targetNamespace="http://main"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:import namespace="http://imported" schemaLocation="file:///C:/.../imp.xsd"/>
    <xsd:element name="Included" type="xsd:string"/>
</xsd:schema>

which in turn is included from "main.xsd":

<xsd:schema targetNamespace="http://main"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:include schemaLocation="file:///C:/.../incl.xsd"/>
    <xsd:complexType name="dummy">
        <xsd:sequence xmlns:impt="http://imported" xmlns:incl="http://main">
            <xsd:element ref="incl:Included"/>
            <xsd:element ref="impt:Imported"/>
        </xsd:sequence>
    </xsd:complexType>
</xsd:schema>

Question: is "main.xsd" a valid xml schema document?

When validated with the xmllint parser (or from python lxml library, which in turn uses xmllint), I get the following error:

Element '{http://www.w3.org/2001/XMLSchema}element', attribute 'ref': References from this schema to components in the namespace 'http://imported' are not allowed, since not indicated by an import statement. WXS schema main.xsd failed to compile

However, another (IBM) parser accepts this XSD without any complaints.

As far as I understand xsd:include, it should behave as if the whole included XSD is inlined into the main document. So, in my opinion, the "main.xsd" should be valid. Is it?

Edit: I was experimenting with xmllint a bit, and when I add the line

<xsd:import namespace="http://imported" schemaLocation="file:///C:/.../imp.xsd"/>

into "main.xsd", xmllint accepts that schema. However, when I add the same line while omitting file:///, I get the following warning:

Element '{http://www.w3.org/2001/XMLSchema}import': Skipping import of schema located at 'C:/.../imported.xsd' for the namespace 'http://imported', since this namespace was already imported with the schema located at 'file:///V:/.../imported.xsd'.

Hence I deduce that the original "main.xsd" is valid and that this is a bug in xmllint.

Upvotes: 0

Views: 1021

Answers (1)

nwellnhof
nwellnhof

Reputation: 33618

See this thread on the [email protected] mailing list. In his answer, Henry S. Thompson quotes following part of the spec:

For a ·QName· to resolve to a schema component [...] the ·namespace name· of the ·QName· is the same as one of the following:

[...]

  • The ·actual value· of the namespace [attribute] of some <import> element information item contained in the <schema> element information item of that schema document [emphasis added].

So indirect imports are not supposed to work.

Upvotes: 1

Related Questions