xerces : Parsingproblem when "include" one or more Schema in another

S

Sascha Hennig

Hi.
My problem is that i parse an xml-document and validate it against a
schema. but the schema has multiple other schemas included (i'm using
"include" not "import" because all schemas using the same namespace).
and the sax parser (from xerces) can't find these schemas, because he
is obviously searching in the wrong directory - in fact in the
dirctory of the application, not in the directory of the including
schema. the path, within the "include" attribute is given relativ to
the including schema.

i'm using java 1.3.1 and have tried different xerces versions. With
xerces 2.0.0 and higher, the sax parser seems not to validate at all.
xerces 1.4.4 do validate but doesn't find the included schemas.

here is the java code:

SAXParser saxParser = new SAXParser();
saxParser.setContentHandler(handler);
saxParser.setErrorHandler(handler);
InputStream ioStream =null;
try
{
saxParser.setFeature
("http://xml.org/sax/features/validation",true);

saxParser.setFeature
("http://apache.org/xml/features/validation/schema", true);

saxParser.setFeature
("http://apache.org/xml/features/validation/schema-full-checking",
true);

InputStreamReader inputstream = new
InputStreamReader(m_oStream,"UTF-8");
InputSource inputsource = new InputSource(inputstream);

saxParser.parse(inputsource);


heres a fragment of the including schema (Reply.xsd) (against this an
xml file is validated)

<xs:schema targetNamespace="www.interface.de" xmlns="www.interface.de"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:include schemaLocation="./KOM.xsd"/>
<xs:include schemaLocation="./Ort.xsd"/>
<xs:element name="Reply">
<xs:complexType name="reply">
<xs:choice>
<xs:sequence>
<xs:element name="AKOM" type="auditkom" minOccurs="0"/>
<xs:element name="AOrt" type="auditort" minOccurs="0"/>
......

these to schemas (KOM, Ort) were not found, when the parser validates
an xml file. all schemas are in the same dirctory (an other then the
application directory). and the absolut path to the Reply.xsd (which
is found) is given in the xml file.

can't sax from xerces handle "include" from xml-schema? or is there a
version wich can?

Thanks & Regards,

Sascha
 
K

Kenneth Stephen

Sascha Hennig said:
Hi.
My problem is that i parse an xml-document and validate it against a
schema. but the schema has multiple other schemas included (i'm using
"include" not "import" because all schemas using the same namespace).
and the sax parser (from xerces) can't find these schemas, because he
is obviously searching in the wrong directory - in fact in the
dirctory of the application, not in the directory of the including
schema. the path, within the "include" attribute is given relativ to
the including schema.
Hi,

I'm guessing that this is probably because the schema main document
lacks a SYSTEM id definition. Declare a SYSTEM id or set the SystemId using
the API to point to the schema file itself and you should be ok (I think).
The include is processed relative to the last System id, and if the id was
deduced because of defaults, the default could very well be the directory
where the "application" xml file is located.

Regards,
Kenneth
 
S

Sascha Hennig

Kenneth Stephen said:
Hi,

I'm guessing that this is probably because the schema main document
lacks a SYSTEM id definition. Declare a SYSTEM id or set the SystemId using
the API to point to the schema file itself and you should be ok (I think).
The include is processed relative to the last System id, and if the id was
deduced because of defaults, the default could very well be the directory
where the "application" xml file is located.

Regards,
Kenneth

Hi.

This recommedation sounds good. But how can I declare a System-Id in
an XML-Schema? I don't know an element which provides the opportunity
to declare a relative system path wich is used to label the path to
included/imported schemas. May be this could help! Please exlpain what
you mean.

Thanks and Regards,

Sascha
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top