I was having a similar problem.  I solved the problem originally by moving the
schema into the directory in which I was running the JVM.  This was a patch and
not a viable solution in the long run.  I eventually found what is called an
EntityResolver.  Since you are using SAX you can use this interface.  The
interface is in the org.xml.sax product and has only one method, resolveEntity,
which basically resolves any external entities.  In your situation the
schemaLocation value, ReqSchema.xsd, is passed in as the systemID string and
then you can create an InputSource based on this value:

public class MyEntityResolver
{
    public InputSource resolveEntity (String publicID, String systemID)
    {
         if (systemID.equals("ReqSchema.xsd")
         {
              FileReader schema = new FileReader("F:\path\to\ReqSchema.xsd");
              return schema;
         }
    }
}

then inorder to notify your SAX parser to use this class when the parser comes
across an external entity event there should be a method (i.e.
setEntityResolver) in your JDOM package (Sorry I couldn't be more specific about
the method name, I am using the dom4j API).

I hope that this helps you with your problem.

Laura

Marcus Schneller wrote:

> hi everybody
>
> i know that this problem is discussed in the FAQ, but i still don't get
> it to work.
>
> I'm trying validating an XML file with an XSD schema.
>
> The XML file looks like this:
>
> ?xml version="1.0" encoding="ISO-8859-1"?>
>
> <Req:Request xmlns:Req="http://www.zhwin.ch/schnemac/Req";
>              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>              xsi:schemaLocation="http://www.zhwin.ch/schnemac/Req
>                                  ReqSchema.xsd">
>
> <Req:URI>eiblet://myEngine/LAYER_EIB_GROUP_OBJECT/bus/Lampe_switch</Req:URI>
>     <Req:Command>switch_on</Req:Command>
> </Req:Request>
>
> ...And the Schema loooks like this:
>
> <?xml version="1.0" encoding="ISO-8859-1"?>
>
> <schema xmlns="http://www.w3.org/2001/XMLSchema";
>         targetNamespace="http://www.zhwin.ch/schnemac/Req";
>     xmlns:Req="http://www.zhwin.ch/schnemac/Req";>
>
>             <element name="URI" type="anyURI" />
>             <element name="Command" type="string" />
>             <element name="Request" type="Req:RequestType" />
>
>     <complexType name ="RequestType">
>             <sequence>
>         <element ref="Req:URI" minOccurs ="0" maxOccurs="1"/>
>         <element ref="Req:Command" minOccurs ="0" maxOccurs="1"/>
>             </sequence>
>     </complexType>
>
> </schema>
>
> When having the validation on, I get a General Schema Error with uri
> "http://www.zhwin.ch/schnemac/Req, not found.
> I'm using the JDOM API and the xerces parser.
>
> The Java code looks like this:
>
> public class InputDocumentHandler{
>
>     private Document doc;
>     private SAXBuilder builder;
>     private Namespace ns;
>
>     public InputDocumentHandler() {
>         builder = new SAXBuilder("org.apache.xerces.parsers.SAXParser",
> ture);
>            builder.setXMLFilter(new SocketFilter());
>     }
>
>
>     public void createDocument(Reader reader) throws JDOMException{
>         try{
>               doc = builder.build(reader);
>               System.out.println(doc.toString());
>               ns = doc.getRootElement().getNamespace();
>         }
>         catch(JDOMException j){
>             throw new JDOMException("Fehler beim Erzeugen des Documents:
> "+ j.getMessage());
>         }
>     }
>
> Strange is, when I use the Validating form "Forte for Java" -Tool, it works.
>
> In wich directory does the parser serch for the Schema?
> Do I have to specify the whole path like F:\path\to\ReqSchema.xsd?
>
> Thanks for any help
>
> Marcus Schneller
>
> ---------------------------------------------------------------------
> 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]

Reply via email to