( Assuming you are using Xerces 1.4.3 Java )
Here is what you can do :
1. Create a class by implementing the interface EntityResolver
- You have to only implement one method - resolveEntity , Here is an example
public InputSource resolveEntity( String publicID, String systemID )
{
InputSource retVal= null;
if ( systemID.indexOf( "ReportRequest.xsd" ) >=0 ) {
File file = new File( "config/" + "ReportRequest.xsd" );
byte [] m_reportRequestSchema = new byte[ (int)file.length() ];
FileInputStream reader = new FileInputStream( file );
reader.read( m_reportRequestSchema,0,(int)file.length() );
retVal = new InputSource( new StringReader( new String( this.m_reportRequestSchema )));
}
else if ( systemID.indexOf( "HaidaConfiguration.xsd" ) >=0 )
......................
......
return retVal;
}
2. When you parse you dont need to set the property as below
m_parser.setProperty( "http://apache.org/xml/properties/schema/external-schemaLocation",
"http://www.mapinfo.com/haida " +
"config/ReportRequest.xsd" );
3. Instead of 2 just create a new instance of the Entity resolver class as in 1.
and set the entity resolver of the class (Parser)
parser.setEntityResolver( new myEntityResolver() );
PS: Note that one thing common to do is to cache the bytestream of the schema files and that way you can avoid
disk access for each parser query. (and just use the persistant bytes to create the InputSource in resolveEntity method in
1 )
Hope this helps
Regards
_______________________________________
Sherif Ahmed
MapInfo Canada Inc. - Toronto
Tel : (416)-609-7776
email: [EMAIL PROTECTED]
Yahoo Messenger id: sherif_ahmed_toronto
web: http://www.mapinfo.com
| "Yeager, Victor R." <[EMAIL PROTECTED]>
10/29/2001 04:34 PM
|
To: [EMAIL PROTECTED] cc: Subject: dynamically setting location of schema files |
Hi!
Does anyone out there know how to dynamically set the expected location of a
schema file before/during parsing XML? I have the following schemaLocation
directive as part of some XML:
<MyTag xmlns="MyNamespace"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="MyNamespace MySchemaFile.xsd">
...
The schema file MySchemaFile.xsd doesn't have a full path name by design.
This isn't a problem if this XML is in a file in the same directory as
MySchemaFile.xsd. But if the XML is in a buffer how can I tell the parser
where to find MySchemaFile.xsd?
Also: is it absolutely necessary that the schema be located in a file? Is it
possible to denote a buffer containing schema to the parser?
Thanks,
Victor Yeager
Nielsen Media Research
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
