This is because when you run code inside an application server you typically
don't have much control over the current working directory. So when you
parse some XML using request.getInputStream() the parser has no idea where
to look for the DTD / XSD file other than the current directory and hence it
can't find it.

The typical way to solve this problem is to attacha SAX EntityResolver to
the SAXReader so that you can read the DTD or schema file from whereever you
wish, the classpath, ServletContext, a website near you or whatever.

There's details here...

http://www.mail-archive.com/dom4j-user@lists.sourceforge.net/msg00829.html

James
-------
http://radio.weblogs.com/0112098/
----- Original Message -----
From: "Sahu, Santosh Kumar" <[EMAIL PROTECTED]>
To: "James Strachan" <[EMAIL PROTECTED]>
Sent: Wednesday, August 21, 2002 2:07 PM
Subject: RE: SchemaValidation problem:please looking for quick reply


HI ,

Thant progme is working fine as a standlalone programe.
but when i run it in OC4j:
i am getting the below:error:

<errors>
  <error column="7" line="1">Document root element "Sale", must match
DOCTYPE root "null".</error>
  <error column="7" line="1">Document is invalid: no grammar found.</error>
</errors>

this is expecting a DTD all the time when i am running in OC4j.
Below is the code:
org.dom4j.io.SAXReader reader = new org.dom4j.io.SAXReader( new
org.apache.xerces.parsers.SAXParser() );
reader.setValidation(true);
reader.setProperty(
"http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation";
,
"gateconex.xsd"
);

XMLErrorHandler errorHandler = new XMLErrorHandler();
reader.setErrorHandler(errorHandler);

document = reader.read(request.getInputStream());

OutputFormat format = new OutputFormat("  ", true);
XMLWriter errorWriter = new XMLWriter(out, format.createPrettyPrint());
Element error=errorHandler.getErrors();

if (error.hasContent())
{
schemaValidation=false;
XMLWriter wr = new XMLWriter(System.out, format.createPrettyPrint());
wr.write(document);
wr.write( errorHandler.getErrors());
}


-----Original Message-----
From: James Strachan [mailto:[EMAIL PROTECTED]]
Sent: 21 August 2002 13:25
To: Sahu, Santosh Kumar
Subject: Re: SchemaValidation problem:please looking for quick reply


> öps thats working great.

Cool.

> can i get u r contact phone number just if there are any production issues
i will call.

Hey this is open source. Its a voluntary thing, so it doesn't come with
phone support. Unless you wanna support contract and gimme some money :-).

James
-------
http://radio.weblogs.com/0112098/
----- Original Message -----
From: "Sahu, Santosh Kumar" <[EMAIL PROTECTED]>
To: "James Strachan" <[EMAIL PROTECTED]>
Sent: Wednesday, August 21, 2002 1:26 PM
Subject: RE: SchemaValidation problem:please looking for quick reply


öps thats working great.

can i get u r contact phone number just if there are any production issues i
will call.


thanks a million.

-----Original Message-----
From: James Strachan [mailto:[EMAIL PROTECTED]]
Sent: 21 August 2002 13:09
To: Sahu, Santosh Kumar; [EMAIL PROTECTED]
Subject: Re: SchemaValidation problem:please looking for quick reply


If you have xerces.jar on your classpath and want to ensure that you use the
Xerces parser with dom4j, irrespective of the presense or configuration of
JAXP or the SAX system property you can do the following...

SAXReader reader = new SAXReader( new
org.apache.xerces.parsers.SAXParser() );
...

That will hardwire xerces in and can save you trouble if your app server,
such as OC4j, tries to force its own parser on you.

James
-------
http://radio.weblogs.com/0112098/
----- Original Message -----
From: Sahu, Santosh Kumar
To: James Strachan
Sent: Wednesday, August 21, 2002 1:02 PM
Subject: RE: SchemaValidation problem:please looking for quick reply


thaks but OC4j appserver from oracle always looking for its own parsers
xmlparserv2.jar but i don `t want to use that.
i have to stop oc4j to use its own parsers which is not possible.
even if i put xerces jar file also it is reading its own.

so as u said i am need to overwrite SAXDRIVER calss to use oracle parser and
then use it.

am i correct?
-----Original Message-----
From: James Strachan [mailto:[EMAIL PROTECTED]]
Sent: 21 August 2002 12:49
To: Sahu, Santosh Kumar
Subject: Re: SchemaValidation problem:please looking for quick reply


Which SAX parser do you wish to use? The bundled aelfred parser doesn't do
validation very well, so I'd suggest using xerces or crimson. I would have
though that one of those comes with Oracle. In which case either add the
JAXP jars (these days its called xml-apis.jar and comes with xerces) to your
classpath or explicitly create the XMLReader / SAXDriver / SAXParser
implementation that comes with the parser you're using, like Xerces.

this line...

     org.dom4j.io.aelfred.SAXDriver  saxdriver=new
org.dom4j.io.aelfred.SAXDriver();

will ensure that the Aelfred parser will always be used, irrespectively of
whether Xerces is on the classpath or not.

James
-------
http://radio.weblogs.com/0112098/
----- Original Message -----
From: Sahu, Santosh Kumar
To: James Strachan
Sent: Wednesday, August 21, 2002 12:45 PM
Subject: RE: SchemaValidation problem:please looking for quick reply


Hi ,
i am trying to use everything from dom4j only.
the code which i am using is as below this :

     org.dom4j.io.aelfred.SAXDriver  saxdriver=new
org.dom4j.io.aelfred.SAXDriver();

   saxdriver.setProperty(

"http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation";
,
    "gateconex.xsd"
   );
   org.dom4j.io.SAXReader reader = new org.dom4j.io.SAXReader();
   reader.setValidation(true);
   XMLErrorHandler errorHandler = new XMLErrorHandler();
   reader.setErrorHandler(errorHandler);
   document = reader.read(request.getInputStream());
   OutputFormat format = new OutputFormat("  ", true);
   XMLWriter errorWriter = new XMLWriter(out, format.createPrettyPrint());
   errorWriter.write( errorHandler.getErrors());

thanks ,
santosh

-----Original Message-----
From: James Strachan [mailto:[EMAIL PROTECTED]]
Sent: 21 August 2002 12:36
To: Sahu, Santosh Kumar
Subject: Re: SchemaValidation problem:please looking for quick reply


which package is SAXDriver from? Which parser (and version) are you trying
to use?

James
-------
http://radio.weblogs.com/0112098/
----- Original Message -----
From: Sahu, Santosh Kumar
To: James Strachan
Sent: Wednesday, August 21, 2002 12:30 PM
Subject: RE: SchemaValidation problem:please looking for quick reply


it is also not working can u please provide a working model using SAXDriver
please.
-----Original Message-----
From: James Strachan [mailto:[EMAIL PROTECTED]]
Sent: 21 August 2002 12:18
To: Sahu, Santosh Kumar; [EMAIL PROTECTED]
Subject: Re: SchemaValidation problem:please looking for quick reply


Hi Santosh

You need to explicitly set the correct SAXDriver implementation on the
SAXReader, either via creating the right Xerces/Crimson XMLReader
implementation, or by adding xml-apis.jar and xerces.jar to your classpath,
then JAXP will be used to find the Xerces parser.

James
-------
http://radio.weblogs.com/0112098/
----- Original Message -----
From: Sahu, Santosh Kumar
To: James Strachan
Sent: Wednesday, August 21, 2002 12:13 PM
Subject: SchemaValidation problem:please looking for quick reply


Hi,

i am using the below code:
    SAXDriver  saxdriver=new SAXDriver();
   SAXReader reader = new SAXReader(saxdriver);
   reader.setValidation(true);
   reader.setProperty(

"http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation";
,
    "gateconex.xsd"
   );

   XMLErrorHandler errorHandler = new XMLErrorHandler();
   reader.setErrorHandler(errorHandler);

   document = reader.read(request.getInputStream());

   OutputFormat format = new OutputFormat("  ", true);
   XMLWriter errorWriter = new XMLWriter(out, format.createPrettyPrint());

   errorWriter.write( errorHandler.getErrors());

when i am running this programe i am getting the below exception:

org.dom4j.DocumentException: Validation not supported for XMLReader:
org.dom4j.io.aelfred.SAXDriver@e Nested exception: http://xml.org/sax/feat
es/validation Nested exception: Validation not supported for XMLReader:
org.dom4j.io.aelfred.SAXDriver@e Nested exception: http://xml.org/sax/f
tures/validation
        org.dom4j.Document
org.dom4j.io.SAXReader.read(org.xml.sax.InputSource)
        org.dom4j.Document org.dom4j.io.SAXReader.read(java.io.InputStream)
        void XMLRequestHandler.<init>(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse, EventBasedSocket, int)
        void GateConex.doPost(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse)
        void
javax.servlet.http.HttpServlet.service(com.evermind.server.http.EvermindHttp
ServletRequest, com.evermind.server.http.EvermindHttpS
vletResponse)
        void
javax.servlet.http.HttpServlet.service(javax.servlet.http.HttpServletRequest
, javax.servlet.http.HttpServletResponse)
        void
javax.servlet.http.HttpServlet.service(javax.servlet.ServletRequest,
javax.servlet.ServletResponse)
        void
com.evermind.server.http.ServletRequestDispatcher.invoke(javax.servlet.Servl
etRequest, javax.servlet.ServletResponse)
        void
com.evermind.server.http.ServletRequestDispatcher.forwardInternal(javax.serv
let.ServletRequest, javax.servlet.http.HttpServletResp
se)
        boolean
com.evermind.server.http.HttpRequestHandler.processRequest(com.evermind.serv
er.ApplicationServerThread, com.evermind.server.htt
EvermindHttpServletRequest,
com.evermind.server.http.EvermindHttpServletResponse, java.io.InputStream,
java.io.OutputStream, boolean)
        void
com.evermind.server.http.HttpRequestHandler.run(java.lang.Thread)
        void com.evermind.util.ThreadPoolThread.run()
Nested exception: org.dom4j.DocumentException: Validation not supported for
XMLReader: org.dom4j.io.aelfred.SAXDriver@e Nested exception: http:
xml.org/sax/features/validation
        void org.dom4j.io.SAXReader.configureReader(org.xml.sax.XMLReader,
org.xml.sax.helpers.DefaultHandler)
        org.dom4j.Document
org.dom4j.io.SAXReader.read(org.xml.sax.InputSource)
        org.dom4j.Document org.dom4j.io.SAXReader.read(java.io.InputStream)
        void XMLRequestHandler.<init>(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse, EventBasedSocket, int)
        void GateConex.doPost(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse)
        void
javax.servlet.http.HttpServlet.service(com.evermind.server.http.EvermindHttp
ServletRequest, com.evermind.server.http.EvermindHttpS
vletResponse)
        void
javax.servlet.http.HttpServlet.service(javax.servlet.http.HttpServletRequest
, javax.servlet.http.HttpServletResponse)
        void
javax.servlet.http.HttpServlet.service(javax.servlet.ServletRequest,
javax.servlet.ServletResponse)
        void
com.evermind.server.http.ServletRequestDispatcher.invoke(javax.servlet.Servl
etRequest, javax.servlet.ServletResponse)
        void
com.evermind.server.http.ServletRequestDispatcher.forwardInternal(javax.serv
let.ServletRequest, javax.servlet.http.HttpServletResp
se)
        boolean
com.evermind.server.http.HttpRequestHandler.processRequest(com.evermind.serv
er.ApplicationServerThread, com.evermind.server.htt
EvermindHttpServletRequest,
com.evermind.server.http.EvermindHttpServletResponse, java.io.InputStream,
java.io.OutputStream, boolean)
        void
com.evermind.server.http.HttpRequestHandler.run(java.lang.Thread)
        void com.evermind.util.ThreadPoolThread.run()
Nested exception: org.xml.sax.SAXNotSupportedException:
http://xml.org/sax/features/validation
        void org.dom4j.io.aelfred.SAXDriver.setFeature(java.lang.String,
boolean)
        void org.dom4j.io.SAXReader.configureReader(org.xml.sax.XMLReader,
org.xml.sax.helpers.DefaultHandler)
        org.dom4j.Document
org.dom4j.io.SAXReader.read(org.xml.sax.InputSource)
        org.dom4j.Document org.dom4j.io.SAXReader.read(java.io.InputStream)
        void XMLRequestHandler.<init>(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse, EventBasedSocket, int)
        void GateConex.doPost(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse)
        void
javax.servlet.http.HttpServlet.service(com.evermind.server.http.EvermindHttp
ServletRequest, com.evermind.server.http.EvermindHttpS
vletResponse)
        void
javax.servlet.http.HttpServlet.service(javax.servlet.http.HttpServletRequest
, javax.servlet.http.HttpServletResponse)
        void
javax.servlet.http.HttpServlet.service(javax.servlet.ServletRequest,
javax.servlet.ServletResponse)
        void
com.evermind.server.http.ServletRequestDispatcher.invoke(javax.servlet.Servl
etRequest, javax.servlet.ServletResponse)
        void
com.evermind.server.http.ServletRequestDispatcher.forwardInternal(javax.serv
let.ServletRequest, javax.servlet.http.HttpServletResp
se)
        boolean
com.evermind.server.http.HttpRequestHandler.processRequest(com.evermind.serv
er.ApplicationServerThread, com.evermind.server.htt
EvermindHttpServletRequest,
com.evermind.server.http.EvermindHttpServletResponse, java.io.InputStream,
java.io.OutputStream, boolean)
        void
com.evermind.server.http.HttpRequestHandler.run(java.lang.Thread)
        void com.evermind.util.ThreadPoolThread.run()



-----Original Message-----
From: James Strachan [mailto:[EMAIL PROTECTED]]
Sent: 19 August 2002 11:15
To: Sahu, Santosh Kumar
Subject: Re: XercesDemo.java example in dom4j is not working.


Try using this script instead. (I've just added this to CVS also).

James
-------
http://james.weblogger.com/
----- Original Message -----
From: Sahu, Santosh Kumar
To: James Strachan
Sent: Monday, August 19, 2002 10:56 AM
Subject: RE: XercesDemo.java example in dom4j is not working.


hi thanks for reply,

i am using the build.bat and run.bat provided by dom4j.
i don`t have a explicit classpath to run this programe.


c:\dom4j\dom4j>run validate.XercesDemo xml\web.xml
Exception occurred: org.xml.sax.SAXNotRecognizedException: Property:
http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation
org.xml.sax.SAXNotRecognizedException: Property:
http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation
       void
org.apache.crimson.parser.XMLReaderImpl.setProperty(java.lang.String,
java.lang.Object)
       void org.dom4j.io.SAXReader.setProperty(java.lang.String,
java.lang.Object)
       org.dom4j.Document validate.XercesDemo.parse(java.lang.String)
       void validate.XercesDemo.run(java.lang.String[])
       void AbstractDemo.run(AbstractDemo, java.lang.String[])
       void validate.XercesDemo.main(java.lang.String[])
c:\dom4j\dom4j>


Myclasspath:
.;c:\jdk1.3.1\lib;c:\antbin\lib;c:\oc4j\j2ee\home\ejb.jar;c:\oc4j\j2ee\home\
jdbc.jar;c:\oc4j\j2ee\home\oc4j.jar;
c:\oc4j\j2ee\home\oc4jclient.jar;c:\oc4j\j2ee\home\orionconsole.jar;c:\oc4j\
jdbc\lib\classes12dms.jar;
c:\oc4j\jdk\jre\lib\ext\jndi.jar;c:\oc4j\j2ee\home\applicationlauncher.jar;c
:\oc4j\j2ee\home\ejbmaker.jar;c:\oc4j\j2ee\home\orion.jar;

this doesn`t contain any crimson or xerces.

your help will be much appreciated.

can i get u r contact details please.







thanks,
santosh
-----Original Message-----
From: James Strachan [mailto:[EMAIL PROTECTED]]
Sent: 19 August 2002 10:34
To: Sahu, Santosh Kumar
Subject: Re: XercesDemo.java example in dom4j is not working.


The stack trace demonstrates the problem - crimson is on your classpath
first, so its not actually using Xerces. You'll need to mess around with
your classpath to put xerces in front of crimson.

James
-------
http://james.weblogger.com/
----- Original Message -----
From: Sahu, Santosh Kumar
To: [EMAIL PROTECTED]
Sent: Monday, August 19, 2002 10:23 AM
Subject: XercesDemo.java example in dom4j is not working.


Hi ,

i will be very thankful if i see a response quickly.

i am getting the below error when i use XercesDemo.java example.
Exception occurred: org.xml.sax.SAXNotRecognizedException: Property:
http://apache.org/xml/properties/schema
org.xml.sax.SAXNotRecognizedException: Property:
http://apache.org/xml/properties/schema/external-noNamespac
        void
org.apache.crimson.parser.XMLReaderImpl.setProperty(java.lang.String,
java.lang.Object)
        void org.dom4j.io.SAXReader.setProperty(java.lang.String,
java.lang.Object)
        org.dom4j.Document validate.XercesDemo.parse(java.lang.String)
        void validate.XercesDemo.run(java.lang.String[])
        void AbstractDemo.run(AbstractDemo, java.lang.String[])
        void validate.XercesDemo.main(java.lang.String[])


i don`t know why?

Thanks,
santosh

__________________________________________________

Do You Yahoo!?

Everything you'll ever need on one web page

from News and Sport to Email and Music Charts

http://uk.my.yahoo.com


__________________________________________________

Do You Yahoo!?

Everything you'll ever need on one web page

from News and Sport to Email and Music Charts

http://uk.my.yahoo.com


__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com


-------------------------------------------------------
This sf.net email is sponsored by: OSDN - Tired of that same old
cell phone?  Get a new here for FREE!
https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to