well, i picked up that with the EntityResolver. The class DefaultHandler in org.xml.sax.helpers does implements this Method. So I have overwritten (extends ; sorry my English) the
public InputSource resolveEntity(String publicId, String systemId) throws SAXException{
}
Method. In my class with the SAXParser I have the Method parser.setEntityResolver(processor);
processor is the objekt of the class wich extends the DefaultHandler.
Well, the method resolveEntity in my DocProccessor class is never called, but the others startElement, endElement ..... are called.
Thats the resolveEntity Method in the class wich extends the DefaultHandler:
public InputSource resolveEntity(String publicId, String systemId) throws SAXException{
System.out.println("Hello");
if (publicId.equals("http://www.zhwin.ch/schnemac/Req") || systemId.equals("ReqSchema.xsd")) {
try{
schema = new FileReader("F:/ZHW/test/ReqSchema.xsd");
}
catch(FileNotFoundException f){
throw new SAXException(f.getMessage());
}
}
return new InputSource(schema);
}
....well, the System.out.println() statement is never reached.
here the code from the parser:
try {
parser = (SAXParser)Class.forName("org.apache.xerces.parsers.SAXParser").newInstance();
parser.setFeature("http://xml.org/sax/features/validation", true);
parser.setContentHandler(processor);
parser.setErrorHandler(processor);
parser.setEntityResolver(processor);
parser.setReaderFactory(new StreamingCharFactory());
}
catch (Exception ex) {
}
Any idea what the problem could be?
thanks for answering
Marcus
Laura Hatcher wrote:
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
?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>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
