Bug 2529 - URI resolving of imported namespaces is not correct
Summary: URI resolving of imported namespaces is not correct
Status: REOPENED
Alias: None
Product: Xerces-J
Classification: Unclassified
Component: Schema-Structures (show other bugs)
Version: 1.4.1
Hardware: PC All
: P1 blocker
Target Milestone: ---
Assignee: Xerces-J Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2001-07-09 23:11 UTC by thomas2.maesing
Modified: 2005-03-20 17:06 UTC (History)
0 users



Attachments
class used for validation (2.54 KB, patch)
2001-07-16 02:41 UTC, thomas2.maesing
Details | Diff
class used as DefaultHandler (1.91 KB, patch)
2001-07-16 02:42 UTC, thomas2.maesing
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description thomas2.maesing 2001-07-09 23:11:19 UTC
Hi,
I have found the following problem:

A relative URI in a import namespace statement like 
<xsd:import namespace="http://www.w3.org/1999/xlink" 
schemaLocation="xlink.xsd"/> is resolved to the URI of
the XML Source to be parsed and not to the containing
XML Schema.

Regards

Thomas
Comment 1 Elena Litani 2001-07-10 06:20:11 UTC
This is not a bug, this is a default behavior. To overwrite this behavior, 
implement your own EntityResolver and register it with a parser.

Look also at: http://nagoya.apache.org/bugzilla/show_bug.cgi?id=2510
Comment 2 thomas2.maesing 2001-07-13 05:43:48 UTC
I have reopened the bug  because I have a further question:

The resolveEntity(String publicId, String systemId) method is called with the 
relative systemId.

How should this method obtain the absolute URI of the XML Schema which contains
this relative URI?

For implementing your suggestion the method should be called with a
resolved absolute URI.

Regards

Thomas
Comment 3 Bernd Eilers 2001-07-13 16:20:06 UTC
The resolveEntity method will always be called with an absolute URI when you 
gave the parser a chance to have some absolute base URI for creating absolute 
URI's from relative ones.

If you use parse(String systemId) you should supply an absolute URI.

If you use parse(InputSource input) you can use setSystemId at the InputSource 
to set the absolute URI.

What you will most likely do in such EntityResolver is either keeping some 
hashtables of public and system identifiers to 'real' locations and than return 
an InputSource created from that 'real' location. For doing this xerces 
contains an nice base class org.apache.readers.XMLCatalogHandler and the 
XCatalog that can load such mappings from a file using an xml based format.

You can also use the EntityResolver to handle your own 
vnd.mycompany.myscheme:/.. URI scheme(s) or do both, eg. if you created the 
InputStream using some application specific procedure that doesn´t map to the 
URI schemes known to xerces like file:// http://.

For resolving relative to absolute URI´s have a look at the java.net.URI class 
in JDK1.4 and http://www.ietf.org/rfc/rfc2396.txt 
Comment 4 thomas2.maesing 2001-07-16 02:40:17 UTC
Okay, with your comment it seems to be a problem with the JAXP Implementation.
I use the method
public void parse(java.io.InputStream is,
                  DefaultHandler dh,
                  java.lang.String systemId)

of javax.xml.parsers.SAXParser.

The method is called with this systemId:
file:/D:/htdocs/xmledi/xml/ssregw_paper_template.xml

And the resolveEntity(String publicId, String systemId) Method than is called 
with the relative URI "ssregw_paper.xsd" which is contained in the InputStream.

I have attched the Java sources. 
Comment 5 thomas2.maesing 2001-07-16 02:41:51 UTC
Created attachment 319 [details]
class used for validation
Comment 6 thomas2.maesing 2001-07-16 02:42:58 UTC
Created attachment 320 [details]
class used as DefaultHandler