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 Kurt Roy <kr...@prospricing.com> on 2007/05/24 01:54:47 UTC

How To Specify an xsd schema in a different directory with schemaLocation attribute - Get "could not find the document" on XML parse

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: kroy@prospricing.com 

Save the Date for the 14th Annual PROS Summit * April 20-23, 2008 at the
Hilton Americas Hotel in Houston, Texas * www.prospricing.com
<http://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



RE: How To Specify an xsd schema in a different directory with schemaLocation attribute - Get "could not find the document" on XML parse

Posted by Kurt Roy <kr...@prospricing.com>.
Thanks!

-----Original Message-----
From: Michael Glavassevich [mailto:mrglavas@ca.ibm.com] 
Sent: Thursday, May 24, 2007 12:15 AM
To: j-users@xerces.apache.org
Subject: RE: How To Specify an xsd schema in a different directory with
<xsd:import> schemaLocation attribute - Get "could not find the
document" on XML parse

InputSource.setSystemId() is the method. More info here [1].

[1] 
http://xerces.apache.org/xerces2-j/javadocs/api/org/xml/sax/InputSource.
html#setSystemId(java.lang.String)

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

"Kurt Roy" <kr...@prospricing.com> wrote on 05/24/2007 01:06:57 AM:

> Where do I specify the base URI??
> 
> Thanks for your help...
> 
> -----Original Message-----
> From: Michael Glavassevich [mailto:mrglavas@ca.ibm.com] 
> Sent: Thursday, May 24, 2007 12:05 AM
> To: j-users@xerces.apache.org
> Cc: nbeyer@gmail.com
> Subject: Re: How To Specify an xsd schema in a different directory
with
> <xsd:import> schemaLocation attribute - Get "could not find the
> document" on XML parse
> 
> nbeyer@gmail.com wrote on 05/23/2007 11:26:19 PM:
> 
> > 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.
> 
> This is the fallback behaviour when no base URI is provided. Usually a

> sign a system ID wasn't set on the InputSource passed to the parse() 
> method or on one returned from an EntityResolver.
> 
> > 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
> 
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org



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



---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


RE: How To Specify an xsd schema in a different directory with schemaLocation attribute - Get "could not find the document" on XML parse

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
InputSource.setSystemId() is the method. More info here [1].

[1] 
http://xerces.apache.org/xerces2-j/javadocs/api/org/xml/sax/InputSource.html#setSystemId(java.lang.String)

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

"Kurt Roy" <kr...@prospricing.com> wrote on 05/24/2007 01:06:57 AM:

> Where do I specify the base URI??
> 
> Thanks for your help...
> 
> -----Original Message-----
> From: Michael Glavassevich [mailto:mrglavas@ca.ibm.com] 
> Sent: Thursday, May 24, 2007 12:05 AM
> To: j-users@xerces.apache.org
> Cc: nbeyer@gmail.com
> Subject: Re: How To Specify an xsd schema in a different directory with
> <xsd:import> schemaLocation attribute - Get "could not find the
> document" on XML parse
> 
> nbeyer@gmail.com wrote on 05/23/2007 11:26:19 PM:
> 
> > 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.
> 
> This is the fallback behaviour when no base URI is provided. Usually a 
> sign a system ID wasn't set on the InputSource passed to the parse() 
> method or on one returned from an EntityResolver.
> 
> > 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
> 
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


RE: How To Specify an xsd schema in a different directory with schemaLocation attribute - Get "could not find the document" on XML parse

Posted by Kurt Roy <kr...@prospricing.com>.
Where do I specify the base URI??

Thanks for your help...

-----Original Message-----
From: Michael Glavassevich [mailto:mrglavas@ca.ibm.com] 
Sent: Thursday, May 24, 2007 12:05 AM
To: j-users@xerces.apache.org
Cc: nbeyer@gmail.com
Subject: Re: How To Specify an xsd schema in a different directory with
<xsd:import> schemaLocation attribute - Get "could not find the
document" on XML parse

nbeyer@gmail.com wrote on 05/23/2007 11:26:19 PM:

> 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.

This is the fallback behaviour when no base URI is provided. Usually a 
sign a system ID wasn't set on the InputSource passed to the parse() 
method or on one returned from an EntityResolver.

> 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

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: How To Specify an xsd schema in a different directory with schemaLocation attribute - Get "could not find the document" on XML parse

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
nbeyer@gmail.com wrote on 05/23/2007 11:26:19 PM:

> 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.

This is the fallback behaviour when no base URI is provided. Usually a 
sign a system ID wasn't set on the InputSource passed to the parse() 
method or on one returned from an EntityResolver.

> 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

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: How To Specify an xsd schema in a different directory with schemaLocation attribute - Get "could not find the document" on XML parse

Posted by Nathan Beyer <nd...@apache.org>.
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 <kr...@prospricing.com> 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: kroy@prospricing.com
>
> 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
>
>
>
>