You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Kopic Benjamin <Be...@emea.eu.int> on 2006/05/08 15:35:34 UTC

Offline validation works on MS Windows but fails under Linux

Hi
 
We use Xerces J 2.7.1 to process XML files that validate against XML Schemata. However, the offline validation fails when run on Linux, although it works fine under MS Windows 2000. The API we use is dom4j ( http://www.dom4j.org/) and JAXP, but I doubt that the problem is in those APIs.
 
This is the code snippet that does the validation:
 
 
reader.setXMLReaderClassName("org.apache.xerces.parsers.SAXParser");
reader.setFeature(" http://apache.org/xml/features/validation/schema", true);
 
String mpdSchemaSource = System.getProperty("mpd-eph");
String messageheaderSchemaSource = System.getProperty("messageheader-eph");
 
String JAXP_SCHEMA_SOURCE = " http://java.sun.com/xml/jaxp/properties/schemaSource";
String JAXP_SCHEMA_LANGUAGE = " http://java.sun.com/xml/jaxp/properties/schemaLanguage";
String W3C_XML_SCHEMA = " http://www.w3.org/2001/XMLSchema";
 
try {
 // retrieve schemata as InputStream from CLASSPATH
 java.io.InputStream _mpd = getClass().getClassLoader().getResourceAsStream(mpdSchemaSource);
 java.io.InputStream _mh = getClass().getClassLoader().getResourceAsStream(messageheaderSchemaSource);
 java.io.InputStream[] _schemas = { _mpd, _mh };
 
 reader.setProperty(JAXP_SCHEMA_SOURCE, _schemas);
 reader.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
}
catch (Exception ex) {
 // log the error
}
 
reader.read(fileObj);
 
if (errorHandler.hasErrors()) {
 // not OK
 // always under Linux
}
else {
 // OK
 // always under MS Windows
}
 
 
The schemata are loaded correctly (I have verified that by outputing the InputStream objects to a file). One of the things we do, however, is using <xsd:import> to import "message-header" schema into "mpd" schema:
 
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema 
 xmlns:xsd=" http://www.w3.org/2001/XMLSchema" 
 xmlns:mh=" http://www.emea.eu.int/EuroPharm/1.0/message-header" 
 xmlns:mpd=" http://www.emea.eu.int/EuroPharm/1.0/mpd" 
 targetNamespace=" http://www.emea.eu.int/EuroPharm/1.0/mpd" 
 elementFormDefault="qualified" 
 attributeFormDefault="unqualified">
 
 <xsd:import schemaLocation="messageheader-eph-1.0.xsd" namespace=" http://www.emea.eu.int/EuroPharm/1.0/message-header"/ <http://www.emea.eu.int/EuroPharm/1.0/message-header> >
 
 <xsd:element name="mpd">
  <xsd:annotation>
   <xsd:documentation>This is a Dictionary feed file format....</xsd:documentation>
  </xsd:annotation>
  <xsd:complexType>
   <xsd:sequence>
    <xsd:element name="messageheader" type="mh:MessageHeader"/>
    <xsd:group ref="mpd:DictionaryEntriesGroup"/>
   </xsd:sequence>
  </xsd:complexType>
 </xsd:element>
 <!-- ... and the rest -->

 
 
The error I get is the following:
 
src-resolve: Cannot resolve the name 'mh:MessageHeader' to a(n) 'type definition' component.
schema_reference.4: Failed to read schema document 'file:///home/oracle/europharm/feed_ben/inbox/messageheader-eph-1.0.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not &lt;xsd:schema&gt;.

 
I suspect the problem is with this import directive in the schema definition, and the error message certainly points to it. The directory, /home/oracle/europharm/feed_ben/inbox/, is the location of XML files, while schemata are located in the CLASSPATH (in a JAR file).
 
Does anyone know how could I resolve this?
 
Best regards,
--
Benjamin Kopic
European Medicines Agency (EMEA)
IT Development - Communications & Networking
7 Westferry Circus
Canary Wharf
London
E14 4HB
Tel. +44(0)20 7523 7417
Fax. +44(0)20 7418 8669
benjamin.kopic@emea.eu.int
 

________________________________________________________________________
This e-mail has been scanned for all known viruses by EMEA.
________________________________________________________________________