I am trying to parse a schema I can learn about it via the xni and psvi api
using Xerces-J version 2.5. However, the schemas that I need to parse import
other schemas from local disk files (a relative path name is specified in
the schemaLocation attribute in the schema), and I am having trouble telling
Xerces how to find the local files. I tried using the
external-schemaLocation property (code included).

However this is not working. I encounter the following problems:

If I pass an odd number of files to setProperty when setting
external-schemaLocation, I get the following error message:

successfully opened file c:\projects\schemaProc\flat\C
SIParty.xsd
[Warning] :-1:-1: SchemaLocation: schemaLocation value =
'file:///c:/projects/ schemaProc/flat/CSICommon.xsd
file:///c:/projects/schemaProc/flat/CSIParty.xsd
file:///c:/projects/schemaProc/flat/Custom.xsd
file:///c:/projects/schemaProc/flat/Party.xsd
file:///c:/projects/schemaProc/flat/CSICustom.xsd
file:///c:/projects/schemaProc/flat/Common.xsd
file:///c:/projects/schemaProc/flat/PaymentMethod.xsd' must have even number
of URI's.

This leads me to think that the external-schemaLocation is expecting pairs
of values (perhaps namemspace, schema location pairs), although it is
documented as expecting just a list of schema location URI's.

When I pass in an even number of schema files, I don't get that error
message, but the parser complains that it is not finding the type
definitions that are in the included files, leading me to believe that the
files are not being imported.

So, my questions are:

1.      What am I doing wrong with my setProperty call?
2.      What is the best way to tell Xerces where to find schema files
referenced in an import statement?
3.      If the import statement specifies a relative file path, is there any
way to tell Xerces where the root of the file path is? 

Here is my java code:

import org.apache.xerces.parsers.XMLGrammarCachingConfiguration;
import org.apache.xerces.xni.grammars.Grammar;
import org.apache.xerces.xni.parser.XMLInputSource;
import org.apache.xerces.xni.grammars.XMLGrammarDescription;
import org.apache.xerces.xni.grammars.XSGrammar;
import org.apache.xerces.impl.xs.psvi.XSModel;

import java.io.Reader;
import java.io.FileReader;

...

public static XSModel parseSchema(Reader r) throws java.io.IOException
    {
        Grammar grammar;
        XMLGrammarCachingConfiguration cacheConfig = new
XMLGrammarCachingConfiguration();
        
 
cacheConfig.setProperty("http://apache.org/xml/properties/schema/external-sc
hemaLocation", 
 "file:///c:/projects/schemaProc/flat/CSICommon.xsd "+
 "file:///c:/projects/schemaProc/flat/CSIParty.xsd "+
 "file:///c:/projects/schemaProc/flat/Custom.xsd "+
 "file:///c:/projects/schemaProc/flat/Party.xsd "+
 "file:///c:/projects/schemaProc/flat/CSICustom.xsd "+
 "file:///c:/projects/schemaProc/flat/Common.xsd "+
 "file:///c:/projects/schemaProc/flat/PaymentMethod.xsd");
        
        XMLInputSource is = new
org.apache.xerces.xni.parser.XMLInputSource(null,null,null,r, null);
        grammar =
cacheConfig.parseGrammar(XMLGrammarDescription.XML_SCHEMA,is);
        
        XSGrammar xsgrammar = (XSGrammar) grammar;
        
        XSModel xsmodel = xsgrammar.toXSModel(); 
        
        return xsmodel;
    }

Here is one of the import statements from the schema that I am trying to
parse:

        <xs:import namespace="http://www.companyX.com/csi/csicommon";
schemaLocation="./CSICommon"/>

Thanks in advance,
Gordon

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to