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.

If I replace the "xsd:include" element with a "xsd:import" element
then I still see problems 1 and 2 above.

I suspect that Problem 1 is a bug in Xerces. However, I am not sure about
Problem 2. Is that a bug? Or am I misunderstanding the division of
responsibilities between Xerces and the application developer? Does the
application developer (that is, me) have to walk the DOM tree to find
all "xsd:include" or "xsd:import" elements and call Xerces to parse each
of the specified files and then somehow merge the multiple parse trees?
If this is the case then I would appreciate some pointers to relevant
parts of the Xerces documentation or demos that illustrate this.


You are assuming that Xerces-C, when parsing an XML Schema document, will interpret Schema-specific elements and/or attributes in some special way. However, this is not true.

If you want to implement an application that interprets the XML Schema include and import elements, you will have to build that yourself. The DOM has APIs that can help you do this, including:

    DOMDocument::getElementsByTagNameNS()
    DOMDocument::importNode()
    DOMNode::appendChild()

Any good tutorial on the DOM will help you figure out how these APIs work.

Dave

Reply via email to