Hi, I was trying to implement LSResourceResolver to load multiple Schemas in my SchemaFactory but I am getting nullpointer Exception. Below is the code. Please tell me what I am missing here ?
Thanks Ajay B. import java.io.*; import java.util.*; import org.w3c.dom.* ; import org.w3c.dom.ls.* ; import org.xml.sax.InputSource; import org.xml.sax.EntityResolver; import java.net.URL; //import org.w3c.dom.ls.DOMImplementationLS; import org.w3c.dom.ls.*; import javax.xml.XMLConstants; import javax.xml.validation.SchemaFactory; import javax.xml.validation.Schema; import org.w3c.dom.bootstrap.DOMImplementationRegistry ; public class SchemaReader { private static int errorCount = 0; String schemaName = null ; public SchemaReader(String st) { System.out.println("debug2"); schemaName = st; System.out.println("debug3"); Schema schema = loadSchema( schemaName ); System.out.println("debug4"); } public static void main(String[] a) { if (a.length<1) { System.out.println("Usage:"); System.out.println("java XsdSchemaValidator schema_file_name " + "xml_file_name"); } else { //String schemaName = a[0]; System.out.println("debug1"); SchemaReader sr = new SchemaReader(a[0]); //Schema schema = sr.loadSchema(schemaName); } } public Schema loadSchema(String name) { Schema schema = null; try { System.out.println("xxx1"); String language = XMLConstants.W3C_XML_SCHEMA_NS_URI; System.out.println("xxx2"); SchemaFactory factory = SchemaFactory.newInstance(language); System.out.println("xxx3"); MyResourceResolver resolver = new MyResourceResolver(); System.out.println("xxx4"); factory.setResourceResolver( resolver ); System.out.println("xxx5"); System.out.println(name); schema = factory.newSchema(new File(name)); System.out.println("xxx6"); } catch (Exception e) { System.out.println(e.toString()); } return schema; } public class MyResourceResolver implements LSResourceResolver { DOMImplementationLS implLS ; public MyResourceResolver() { try { System.setProperty(DOMImplementationRegistry.PROPERTY, "org.apache.xerces.dom.DOMImplementationSourceImpl"); DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementation domImpl = registry.getDOMImplementation("LS 3.0"); DOMImplementationLS implLS = (DOMImplementationLS)domImpl; } catch ( Exception e) { System.out.println("xxx"); System.out.println(e.toString()); } } public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI ) { LSInput input = implLS.createLSInput(); System.out.println("System Id :" + systemId); System.out.println("Base URI :" + baseURI); FileInputStream fis = null; try { fis = new FileInputStream(new File(systemId)); } catch(Exception e) { System.out.println("debug1"); System.out.println(e.toString()); } input.setByteStream(fis); input.setSystemId(systemId); return input ; //return fis ; } } } Output ======== debug1 debug2 debug3 xxx1 xxx2 xxx3 xxx4 xxx5 clpt.001.001.01.xsd java.lang.NullPointerException debug4 --- On Tue, 11/11/08, ajay bhadauria <[EMAIL PROTECTED]> wrote: > From: ajay bhadauria <[EMAIL PROTECTED]> > Subject: Re: use of ResourceResolver in Schema Parsing > To: j-users@xerces.apache.org > Date: Tuesday, November 11, 2008, 7:35 PM > Hi, > > I could not figure out how to implement LSResourceResolver > with SchemaFactory so that all external entities could be > loaded when main schema gets loaded. > > Any code sample will be greatly appriciated . > > Thanks > > --- On Mon, 11/10/08, ajay bhadauria > <[EMAIL PROTECTED]> wrote: > > > From: ajay bhadauria <[EMAIL PROTECTED]> > > Subject: use of ResourceResolver in Schema Parsing > > To: j-users@xerces.apache.org > > Date: Monday, November 10, 2008, 8:24 PM > > Hi, > > > > I am using SchemaFactory and then from factory I am > setting > > setResourceResolver to resolve external entities. > while > > reading schema which refers to other schemas through > import > > and include, but I am not able to construct LSInput in > > resolveResource method of LSResourceResolver > interface. > > > > What should I do to construct the LSInput in > > resolveResource method ? > > > > Please find the attached java file. Please help me how > I > > should do it ? > > > > Regards > > > > Ajay > > > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: > > [EMAIL PROTECTED] > > For additional commands, e-mail: > > [EMAIL PROTECTED] > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: > [EMAIL PROTECTED] > For additional commands, e-mail: > [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]