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


      
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 javax.xml.XMLConstants;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Schema;

public class SchemaReader 
{

  private static int errorCount = 0;
  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];
         Schema schema = loadSchema(schemaName);
     }
   }

  public static Schema loadSchema(String name) 
  {
    Schema schema = null;
    try 
    {
      String language = XMLConstants.W3C_XML_SCHEMA_NS_URI;
      SchemaFactory factory = SchemaFactory.newInstance(language);
      MyResourceResolver resolver = new MyResourceResolver();
      factory.setResourceResolver( resolver );
      schema = factory.newSchema(new File(name));

    } 
    catch (Exception e) 
    {
      System.out.println(e.toString());
    }
     return schema;
  }


  public static class MyResourceResolver implements LSResourceResolver 
  {
           private DOMImplementationLS domImplementationLS = new 
DOMImplementationLS();
           public LSInput resolveResource(String type, String namespaceURI, 
String publicId, String systemId, String baseURI ) 
           {
                 
                LSInput ret = domImplementationLS.createLSInput();

                FileInputStream fis =  null;
                try
                {
                     fis =  new FileInputStream((new URL(systemId)).getPath());
                }
                catch(Exception e)
                {
                     System.out.println(e.toString());
                }

                ret.setSystemId(systemId);
                return ret.setByteStream(fis);

            }


   }

}

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

Reply via email to