I believe the default behavior for loading relative paths is to
resolve them against the "working directory" of the JRE, which would
be similar to passing a relative path to a File constructor.

To provide more deterministic resolution, you can use the
EntityResolver interface [1] if you're using SAX parsing. If you're
using a more recent JAXP version, such as what's available in Java 5,
you can setup an LSResourceResolve [2] on a SchemaFactory [3].

I've never personally tried the later.

-Nathan

[1] http://java.sun.com/j2se/1.5.0/docs/api/org/xml/sax/EntityResolver.html
[2] 
http://java.sun.com/j2se/1.5.0/docs/api/org/w3c/dom/ls/LSResourceResolver.html
[3] 
http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/validation/SchemaFactory.html

On 5/23/07, Kurt Roy <[EMAIL PROTECTED]> wrote:




Hello,



I am trying to import one xsd schema into another via the xsd:import
statement. The files are in the following directories:



./appgen/config/ApplicationSchema.xsd  <- - - the xsd doing
the importing

./appgen/config/xsd/ConfigurableDimensionsContext.xsd



In ApplicationSchema.xsd, I have specified:



<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";
elementFormDefault="unqualified">



  <xsd:import namespace="http://prosrm.com/appgen";


schemaLocation="xsd/ConfigurableDimensionsContext.xsd" />



    . . .



This is referenced in an XML as follows:



<Application

 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";

xsi:noNamespaceSchemaLocation="../appgen/config/ApplicationSchema.xsd">



. . .



This xml file is located in directory:



 ./scf/



(./scf is at the same level as ./appgen).



When I try to parse with xerces, I get this error:



     [java] - Unrecoverable warning parsing input SCF:
C:\prosrm\pricing/../scf/

PricingDemo.xml

     [java] org.xml.sax.SAXParseException: schema_reference.4: Failed to
read sc

hema document 'xsd/ConfigurableDimensionsContext.xsd',
because 1) could not find

 the document; 2) the document could not be read; 3) the root element of the
doc

ument is not <xsd:schema>.

     [java]     at
org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseExce

ption(Unknown Source)

     [java]     at
org.apache.xerces.util.ErrorHandlerWrapper.warning(Unknown
So

urce)

     [java]     at
org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown
S

ource)



Note that it could not find the file, even though the *relative* path in the
"schemaLocation" attribute matches the path referenced in the error message
above, and it is correct.



Furthermore (and a bit confusing to me), is IF I have
ConfigurableDimensionsContext.xsd in the same directory as
the importing ApplicationSchema.xsd, it is found, and all is OK.



It seems like the parser is taking just the file name (stripping off the
relative dir) of the schemaLocation attribute, and looking for that name in
the current directory.



Is this correct? Is that the correct behavior? Or am I doing something
wrong?



I would like the import xsds to be in a different directory than the main
one. How can I get this to work?



Thanks in advance,

Kurt Roy | PROS | Software Architect, Software Development
 phone: +1 713-335-8007 | email: [EMAIL PROTECTED]

Save the Date for the 14th Annual PROS Summit • April 20-23, 2008 at the
Hilton Americas Hotel in Houston, Texas • www.prospricing.com




________________________________
 The information contained in this email may be confidential and/or legally
privileged. It has been sent for the sole use of the intended recipient(s).
If the reader of this message is not an intended recipient, you are hereby
notified that any unauthorized review, use, disclosure, dissemination,
distribution, or copying of this communication, or any of its contents, is
strictly prohibited. If you have received this communication in error,
please contact the sender by reply email and destroy all copies of the
original message. Thank you




Reply via email to