Ciaran McHale wrote:
> Hi folks,
>
> I am using Xerces C++ 2.7.0. Mostly, it works great, but I am finding
> some unexpected behavior with "xsd:include" and "xsd:import" (where
> "xsd" denotes the XML Schema namespace). The "included.xsd" file below
> illustrates the problem.
>
> ----start of "included.xsd" file----
> <?xml version="1.0" encoding="UTF-8"?>
> <xsd:schema
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified"
> targetNamespace="http://www.lanw.com/namespaces/pub"
> xmlns="http://www.lanw.com/namespaces/pub">
>
> <xsd:include schemaLocation = "foo.xsd"/>
>
> </xsd:schema>
> ----end of "included.xsd" file----
>
> Near the end of this email I provide the relevant piece of code that I
> use to parse the file.
>
> If the included file ("foo.xsd") exists and contains a (deliberate)
> error then Xerces reports the error. So far, so good.
>
> Problem 1
> ---------
> If the included file ("foo.xsd") does not exist then I would expect
> Xerces to report an error, but Xerces just silently ignores the error.
>
> Problem 2
> ---------
> If the included file ("foo.xsd") exists and does not contain any
> errors then Xerces parses everything okay. However, the resultant DOM
> tree does not contain any nodes from the included file. This surprised
> me because Xerces is a Schema-validating parser and "xsd:include" is
> part of XML schema so I assumed that Xerces would insert contents of
> the included file in the DOM tree.
Hi Ciaran,
what are you going to do? Are you parsing xml files and validate them
against your schemas - or are you parsing schema files and treat them as
xml?
In the former case, xsl:include and xsl:import behave as you suspect,
i.e. the referenced files are fetched and their contents fed into the
grammar, recursively.
In the latter case, you are self responsible to interpret the schema
tags, since as they are treated as xml, not as schema. Your code shows
that you switch off validation when you suspect to parse a schema (which
is fully correct). What are you planning to do with a DOM tree that
contains a schema?
Maybe, there is some confusion about the way xerces checkes against
schemata. The checking is done (neary) invisibly, and the schema
contents can be accessed via grammar objects, not via DOM trees.
Could I get some light into your scene?
Cheers,
Axel