xerces-j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Anders Kristensen <akristen...@dynamicsoft.com>
Subject Re: Antwort: programmatically resolving namespaces to local schemas
Date Fri, 25 Apr 2003 23:25:00 GMT

thomas2.maesing@bgs-ag.de wrote:
> Hi,
> just try the setEntityResolver Method of the XMLReader or the
> DocumentBuilder.
> It works also for XML Schemas.

Thanks, that should probably have been obvious to me. Might be 
worthwhile adding an FAQ item anyway, though.

Of course, I'm still running into problems. When resolving an HTTP 
system URL specified with xsd:schemaLocation to a local .xsd file, the 
parser seems either not to read the xsd InputSource I return from my sax 
EntityResolver, or else the semantics changes somehow. The xsd file 
contains a declaration of a named model group

The following is my attempt to produce a minimal example that 
illustrates the problem. I have two schemas with the same 
targetNamespace: foo.xsd specifies common stuff (a single named model 
group, "DescriptionGroup") while bar.xsd includes foo.xsd and defines a 
"bar" root element whose content model refers to the DescriptionGroup. 
The foobar.xml instance conforms to the bar/foo schemas and specifies a 
schemaLocation pointing to the bar.xsd resource (a file: URL).

Now, when I parse *without* resolving the file: URL, I get no parse 
error but when I resolve the file: URL to a local resource (using 
Class.getResourceAsStream to find the xsd file relative to the 
classpath), I get the following error:

[Error] :13:48: src-resolve: Cannot resolve the name 
'foo:DescriptionGroup' to a (n) group component.

When I look at last accessed times for the local xsd files, it seems 
that bar.xsd isn't actually read by the parser even though I returned an 
InputStream for it in my EntityResolver:

$ java FooBarParser foobar.xml
resolved entity 'file:/c:/foobar/bar.xsd' to '/bar.xsd'
resolved entity 'file:/c:/foobar/foo.xsd' to '/bar.xsd'
[Error] :13:48: src-resolve: Cannot resolve the name 
'foo:DescriptionGroup' to a (n) group component.
startElement: bar       [http://dynamicsoft.com/xml/ns/foo]
startElement: description       [http://dynamicsoft.com/xml/ns/foo]
startElement: comment   [http://dynamicsoft.com/xml/ns/foo]
$ ls -lu *xsd
-rwxrwxrwx    1 65535    mkgroup       625 Apr 25 19:05 bar.xsd
-rwxrwxrwx    1 65535    mkgroup       452 Apr 25 18:49 foo.xsd

So it seems that for some reason the parser just isn't reading foo.xml 
when I resolve the <xsd:include> schemaLocation.  Is there some way to 
get the parser to emit debug or trace information to get more info on 
the processing it's performing?

Secondly, I noticed that although I've specified that I want schema 
validation enabled (with the 
"http://apache.org/xml/features/validation/schema" feature), I can 
modify bar child elements (but not the bar element itself) to be 
anything and have parsing still succeed as long as I don't resolve the 
schemaLocation URLs.

I've attached the foo.xsd and bar.xsd schemas and the foobar doc 
instance as well as the Java class used for parsing. The schemaLocation 
file: URLs assume all is in a single directory c:/foobar. Running 
FooBarParser with a -Dnoresolve system property disables the entity 

Any help *much* appreciated. Trying to figure this stuff out can be 
pretty frustrating ;)


View raw message