Toby Saville wrote:

>I tried using the file protocol in the doctype, similar to my original post,
>ie:
><!DOCTYPE maps SYSTEM
>"file:///d:/Projects/portfolio/webapps/xml/metadata.xml">
>
>And this worked. But isnt this defeating the multiplatform and
>distributability benefits of Java and webapps as you mentioned before? Is
>there an alternative?
>
You should reference your DTD using "http instead of file. This way the 
parser will always be able to locate your DTD.  If you don't have 
another web server to server your DTD, you can put a fake "http" and, 
with your SAX parser, you can create your own EntityResolver class and 
then intercept the call to the remote DTD and redirect it to a local 
copy (now using the "fille..." way).

Just take a look at the common-digester project. This is the way we are 
solving that problem....and you may want to use the Digester itself. 
Much more easy that using SAX directly ;-)

http://jakarta.apache.org/commons/digester.html

-- Jeanfrancois

>
>Thanks again.
>
>t0bes
>
>-----Original Message-----
>From: Toby Saville 
>Sent: Monday, 23 September 2002 1:37 PM
>To: 'Tomcat Users List'
>Subject: RE: FW: XML Parsing in Servlet
>
>
>Thanks for your help Jake,
>
>I created an inputstream the way you said and passed it to the XML parser
>but it stopped at the same point. I realised that i had set my DOCTYPE
>definition to http://127.0.0.1/xml/metadata.xml. I figured this could be a
>problem as the web server isnt yet started when the validation takes place.
>So i changed my doctype from:
><!DOCTYPE maps SYSTEM "http://127.0.0.1/xml/maps.dtd";>
>to:
><!DOCTYPE maps SYSTEM "maps.dtd">
>but now i get the following exception:
>java.net.MalformedURLException: no protocol: maps.dtd
>
>Is it time to post this question to an XML forum or are you able to tell me
>how i should specify my doctype?
>
>thanks again,
>
>t0bes
>
>-----Original Message-----
>From: Jacob Kjome [mailto:[EMAIL PROTECTED]]
>Sent: Monday, 23 September 2002 1:16 PM
>To: Tomcat Users List
>Subject: Re: FW: XML Parsing in Servlet
>
>
>
>Stay away from File IO in webapps anyway.  Use an InputStream if at all 
>possible.  You've made your app work on Windows only which defeats the 
>purpose of the multi-platform and distibutability benefits of Java and 
>webapps.  Also, if you run your app out of a .war file and the file you are 
>trying to access is inside that .war file, your app will fail because there 
>is no File IO that can be done within the archive.  Try using this
>instead....
>
>InputStream is = getServletContext().getResourceAsStream("/foo.txt");
>
>That loads foo.txt from the root of your webapp, wherever that is.  This 
>will work on any platform and even in the case where you serve your webapp 
>directly from a .war file.
>
>Jake
>
>
>
>At 12:08 PM 9/23/2002 +1000, you wrote:
>  
>
>>Hi,
>>
>>back again, i sent my last email without writing what standard out prints.
>>Here it is:
>>
>>Starting service Tomcat-Standalone
>>Apache Tomcat/4.1.10
>>
>>Sorry for re posting.
>>
>>-t0bes
>>
>>
>>
>>-----Original Message-----
>>From: Toby Saville
>>Sent: Monday, 23 September 2002 12:06 PM
>>To: 'Tomcat Users List'
>>Subject: XML Parsing in Servlet
>>
>>
>>Hi,
>>
>>Im not sure if this is the correct place to post this type of message but
>>ill try anyways.
>>
>>Im trying to parse an XML file in a servlet's init(Servlet config) method
>>    
>>
>on
>  
>
>>a tomcat4.1 server. I am using a xerces SAX parser. The servlet has a
>>load-on-startup tag in web.xml with a value of 1.
>>
>>When i attempt to parse the file in the init method, the loading of the web
>>server stops.
>>The standard output prints up to:
>>
>>The log file outputs up to "starting filters", but nothing else. i pass a
>>URI compliant string to the parser which looks like this:
>>file:///d:/Projects/portfolio/webapps/xml/metadata.xml
>>
>>I can create a File object using this URI and look at its details in the
>>init method, but as soon as i say parser.parse(fileURI, handler); the
>>loading of tomcat stops.
>>
>>Any ideas why this could be?
>>
>>Thanks
>>
>>-Tobes
>>
>>
>>***************************************************************
>>This message is intended for the addressee named and
>>may  contain confidential information. If you are not the
>>intended recipient, please delete it and notify the sender.
>>Views expressed in this message are those of the
>>individual sender, and are not necessarily the views of the
>>Department of  Information Technology & Management.
>>
>>This email message has been swept by MIMEsweeper
>>for the presence of computer viruses.
>>***************************************************************
>>    
>>
>
>
>***************************************************************
>This message is intended for the addressee named and 
>may  contain confidential information. If you are not the 
>intended recipient, please delete it and notify the sender. 
>Views expressed in this message are those of the 
>individual sender, and are not necessarily the views of the
>Department of  Information Technology & Management.
>
>This email message has been swept by MIMEsweeper 
>for the presence of computer viruses.
>***************************************************************
>
>
>  
>

Reply via email to