Discussion:
XSLoader can not load XSD which include relative schemaLocation while absolute path works
Xiaofeng Zhang
2008-05-07 01:04:27 UTC
Permalink
Hi,

We use XSLoader to load XML schema. If the xsd file include relative
schemaLocation a warning is thrown:

[Warning] :2:46: schema_reference.4: Failed to read schema document
'../base.xsd', because 1) could not find the document; 2) the document
could not be read; 3) the root element of the document is not
<xsd:schema>.



Changing to absolute path <xsd:include
schemaLocation="file:///C:/.../base.xsd"/> the XSLoader will work.

Is this a bug?



The attached file is a schema example.



Regards,

Xiaofeng
Michael Glavassevich
2008-05-07 03:21:03 UTC
Permalink
Hi Xiaofeng,

Did you provide a URI when you parsed the document using XSLoader? A common
usage error is specifying an InputStream or Reader and not providing a
system ID as the base URI. Without providing a base URI the schema loader
will fall back to using the current working directory (the value of the
system property user.dir) as the base URI for resolution.

Thanks.

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
Post by Xiaofeng Zhang
Hi,
We use XSLoader to load XML schema. If the xsd file include relative
[Warning] :2:46: schema_reference.4: Failed to read schema document
'../base.xsd', because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is
not <xsd:schema>.
Changing to absolute path <xsd:include
schemaLocation="file:///C:/.../base.xsd
Post by Xiaofeng Zhang
"/> the XSLoader will work.
Is this a bug?
The attached file is a schema example.
Regards,
Xiaofeng
---------------------------------------------------------------------
Michael Glavassevich
2008-05-10 14:55:01 UTC
Permalink
Hi Xiaofeng,

The problem is in your code. Windows file paths aren't URIs however that is
what you're setting as the base URI on the LSInput. Even if it were correct
you need to set a system ID for it to have an effect. You're also doing a
number of unnecessary things in setting up the input, including one
(wrapping an InputStream in an InputStreamReader) which can lead to
encoding errors.

Keep it simple. I'm sure if you try this it will work:

public static void main( String[] args ) throws URISyntaxException
{
File f = new File( "C:/226232/package/my.xsd" );
XSLoader xsLoader = new XMLSchemaLoader( );
XSModel xsModel = xsLoader.loadURI( f.toURI().toString() );
}

Thanks.

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
Hi,
I have modified my code to provide a base URI. But the problem still
exists.
The followed test case can be used to reproduce the bug. The
attached file contain the schema files used in this case. Is there
other error in my case?
public class Test
{
/**
*/
public static void main( String[] args ) throws URISyntaxException
{
File f = new File( "C:/226232/package/my.xsd" );
URI uri = f.toURI( );
XSLoader xsLoader = new XMLSchemaLoader( );
LSInput input = new DOMInputImpl( );
try
{
input.setCharacterStream( new BufferedReader( new
InputStreamReader( uri.toURL( )
.openStream( ) ) ) );
System.out.println( f.getParent( ) );
input.setBaseURI( f.getParent( ) );
}
catch ( IOException e )
{
System.out.println( e.toString( ) );
}
XSModel xsModel = xsLoader.load( input );
}
}
Regards,
Xiaofeng
-----Original Message-----
Sent: 2008Äê5ÔÂ9ÈÕ 11:19
To: Xiaofeng Zhang
Subject: [jira] Resolved: (XERCESJ-1307) XSLoader can not load XSD
which include relative schemaLocation while absolute path works
[ https://issues.apache.org/jira/browse/XERCESJ-1307?page=com.
atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Michael Glavassevich resolved XERCESJ-1307.
-------------------------------------------
Resolution: Cannot Reproduce
Hi, you asked a question about this on the j-users mailing list but
then didn't respond [1] to my answer. It's highly likely that this
is a usage error. Marking this as "Cannot Reproduce" unless you have
a valid test case (including Java code) which you could post here
which shows otherwise.
[1] http://marc.info/?l=xerces-j-user&m=121013050120821&w=2
XSLoader can not load XSD which include relative schemaLocation
while absolute path works
-----------------------------------------------------------------------------------------
Key: XERCESJ-1307
URL: https://issues.apache.org/jira/browse/XERCESJ-1307
Project: Xerces2-J
Issue Type: Bug
Components: XML Schema API
Affects Versions: 2.9.0
Environment: Window XP
Reporter: xiaofeng.zhang
Fix For: 2.9.0
We use XSLoader to load XML schema. If the xsd file include
[Warning] :2:46: schema_reference.4: Failed to read schema
document '../base.xsd', because 1) could not find the document; 2)
the document could not be read; 3) the root element of the document
is not <xsd:schema>.
/.../base.xsd"/> the XSLoader will work.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[attachment "226232.zip" deleted by Michael Glavassevich/Toronto/IBM]
Michael Glavassevich
2008-05-12 03:44:39 UTC
Permalink
Hi Xiaofeng,

There's a setEncoding() method on LSInput but you shouldn't need to use it
if the encoding is declared [1] in the document (in which case the parser
will figure it out itself).

Thanks.

[1] http://www.w3.org/TR/2004/REC-xml-20040204/#charencoding

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
Hi Michael,
Thanks for your reply. I have another question. We need to support
all kinds of character encoding (such as "gb2312","Big5"). How can I
tell XSLoader the character encoding of the XML document.
Regards,
Xiaofeng
-----Original Message-----
Sent: 2008Äê5ÔÂ10ÈÕ 22:55
Cc: Xiaofeng Zhang
Subject: Re: XSLoader can not load XSD which include relative
schemaLocation while absolute path works
Hi Xiaofeng,
The problem is in your code. Windows file paths aren't URIs however
that is what you're setting as the base URI on the LSInput. Even if
it were correct you need to set a system ID for it to have an
effect. You're also doing a number of unnecessary things in setting
up the input, including one (wrapping an InputStream in an
InputStreamReader) which can lead to encoding errors.
public static void main( String[] args ) throws URISyntaxException
{
File f = new File( "C:/226232/package/my.xsd" );
XSLoader xsLoader = new XMLSchemaLoader( );
XSModel xsModel = xsLoader.loadURI( f.toURI().toString() );
}
Thanks.
Michael Glavassevich
XML Parser Development
IBM Toronto Lab
Hi,
I have modified my code to provide a base URI. But the problem still
exists.
The followed test case can be used to reproduce the bug. The
attached file contain the schema files used in this case. Is there
other error in my case?
public class Test
{
/**
*/
public static void main( String[] args ) throws URISyntaxException
{
File f = new File( "C:/226232/package/my.xsd" );
URI uri = f.toURI( );
XSLoader xsLoader = new XMLSchemaLoader( );
LSInput input = new DOMInputImpl( );
try
{
input.setCharacterStream( new BufferedReader( new
InputStreamReader( uri.toURL( )
.openStream( ) ) ) );
System.out.println( f.getParent( ) );
input.setBaseURI( f.getParent( ) );
}
catch ( IOException e )
{
System.out.println( e.toString( ) );
}
XSModel xsModel = xsLoader.load( input );
}
}
Regards,
Xiaofeng
-----Original Message-----
Sent: 2008Äê5ÔÂ9ÈÕ 11:19
To: Xiaofeng Zhang
Subject: [jira] Resolved: (XERCESJ-1307) XSLoader can not load XSD
which include relative schemaLocation while absolute path works
[ https://issues.apache.org/jira/browse/XERCESJ-1307?page=com.
atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Michael Glavassevich resolved XERCESJ-1307.
-------------------------------------------
Resolution: Cannot Reproduce
Hi, you asked a question about this on the j-users mailing list but
then didn't respond [1] to my answer. It's highly likely that this
is a usage error. Marking this as "Cannot Reproduce" unless you have
a valid test case (including Java code) which you could post here
which shows otherwise.
[1] http://marc.info/?l=xerces-j-user&m=121013050120821&w=2
XSLoader can not load XSD which include relative schemaLocation
while absolute path works
-----------------------------------------------------------------------------------------
Key: XERCESJ-1307
https://issues.apache.org/jira/browse/XERCESJ-1307
Project: Xerces2-J
Issue Type: Bug
Components: XML Schema API
Affects Versions: 2.9.0
Environment: Window XP
Reporter: xiaofeng.zhang
Fix For: 2.9.0
We use XSLoader to load XML schema. If the xsd file include
[Warning] :2:46: schema_reference.4: Failed to read schema
document '../base.xsd', because 1) could not find the document; 2)
the document could not be read; 3) the root element of the document
is not <xsd:schema>.
/.../base.xsd"/> the XSLoader will work.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
Loading...