[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: load DTD in memory.

  • From: Nicolas LEHUEN <nicolas.lehuen@u...>
  • To: 'Giuseppe Sarno' <gsarno@n...>,"'xml-dev@l...'" <xml-dev@l...>
  • Date: Fri, 07 Sep 2001 12:36:13 +0200

dtd cache
Title: RE: load DTD in memory.
Well if you are loading many documents with the same DTD, you'll have improvements. If your documents DTDs are all differents, then you should consider having a persistent DTD cache, i.e. storing DTD as files and associating these files to their PUBLIC id. This is a kind of DTD catalog.
 
-----Message d'origine-----
De : Giuseppe Sarno [mailto:gsarno@n...]
Envoyé : vendredi 7 septembre 2001 12:31
À : Nicolas LEHUEN; 'xml-dev@l...'
Objet : RE: load DTD in memory.

Hi I implemented this,
but apparently I didn't get any improvements.
I was expecting to be very quick.
Is it possible ?
 
cheers.
-----Original Message-----
From: Nicolas LEHUEN [mailto:nicolas.lehuen@u...]
Sent: 06 September 2001 16:10
To: Sarno, Giuseppe [MAIFP:GM12:EXCH]; 'xml-dev@l...'
Subject: RE: load DTD in memory.

Oops sorry I wrote the code directly in the mail, without compiling it :). You should have read (and corrected) :
 
InputStream isP=urlP.openStream();
 
Do not hesitate to have a look at the Javadoc to solve such problems. That's a must if you want to achieve fast development in Java : always have your Javadoc at hand.
 
Regards,
Nicolas
-----Message d'origine-----
De : Giuseppe Sarno [mailto:gsarno@n...]
Envoyé : jeudi 6 septembre 2001 11:33
À : Nicolas LEHUEN; 'xml-dev@l...'
Objet : RE: load DTD in memory.

hi I'm getting error on

InputStream isP=urlP.openConnection();
Incompatible type for declaration. Can't convert java.net.URLConnection to java.io.InputStream.
                        InputStream isP=urlP.openConnection();
                                    ^
1 error

what should i do for that ?

cheers.

-----Original Message-----
From: Nicolas LEHUEN [mailto:nicolas.lehuen@u...]
Sent: 05 September 2001 14:09
To: Sarno, Giuseppe [MAIFP:GM12:EXCH]; 'xml-dev@l...'
Subject: RE: load DTD in memory.


Well, here is a sample class for a in-memory entity cache (it will therefore
cache DTDs). It is a dumb cache, because if the original DTD changes, the
cache is not refreshed, but for many cases it is sufficient. We have
implemented a much more flexible caching framework, but here it's out of
scope.

import java.net.*;
import java.util.*;
import org.xml.sax.*;

public class DTDMemoryCache implements EntityResolver {
    private Map cache=new HashMap();

    // Remember to handle synchronization issues !!
    // A dumb but easy implementation would synchronize the whole
    // resolveEntity method
    public synchronized InputSource resolveEntity(String publicIdP,String
systemIdP) throws SAXException {
        // The PUBLIC id is the key to our cache
        byte[] resultP=cache.get(publicIdP);

        if(resultP==null) {
            try {
                        // The SYSTEM id is the URL used to fetch the entity
                        URL urlP=new URL(systemIdP);
                        InputStream isP=urlP.openConnection();
                        ByteArrayOutputStream baosP=new
ByteArrayOutputStream();

                        // We copy the input stream into the output stream
                        // Fast buffer implementation
                        // I could have used BufferInputStream and
OutputStream
                        // But it's much slower
                        int readP;
                        byte[] bufferP=new byte[1024];
                        while((readP=isP.read(bufferP))>-1) {
                                baosP.write(bufferP,0,readP);
                        }

                        resultP=baosP.toByteArray();
                       
                        // We store the result in the cache.
                        cache.put(publicIdP,resultP);
            }
            catch(Exception eP) {
                throw new SAXException(eP);
            }
        }

        return new InputSource(new ByteArrayInputStream(resultP));
    }
}

Now, how to install this EntityResolver ? Both the org.xml.sax.Parser and
the javax.xml.parsers.DocumentBuilder have a setEntityResolver() method that
enables you to install your own EntotyResolver before parsing your
documents.

Regards,
Nicolas

-----Message d'origine-----
De : Giuseppe Sarno [mailto:gsarno@n...]
Envoyé : mercredi 5 septembre 2001 14:47
À : Nicolas LEHUEN; 'xml-dev@l...'
Objet : RE: load DTD in memory.


hi,
thanks for your answer,
but could you please tell me more on how to do it since the API doc doesn't
explain it very well.

cheers.
-----Original Message-----
From: Nicolas LEHUEN [mailto:nicolas.lehuen@u...]
Sent: 05 September 2001 13:26
To: Sarno, Giuseppe [MAIFP:GM12:EXCH]; 'xml-dev@l...'
Subject: RE: load DTD in memory.


To cache DTDs the easiest thing to do with SAX is to implement your own
EntityResolver. This way you'll be able to cache locally or in memory all
entities, amongst them the DTDs.

Regards,
Nicolas
-----Message d'origine-----
De : Giuseppe Sarno [mailto:gsarno@n...]
Envoyé : mercredi 5 septembre 2001 13:56
À : xml-dev@l...
Objet : load DTD in memory.


Hi ,
I was wondering ,
in case is needed to parse a lot of XML docs , is it possible to
load the DTD or Schema one in memory and always reuse it instead of
reloading it for each Doc validation ?
cheers.
--------------InterScan_NT_MIME_Boundary--
--------------InterScan_NT_MIME_Boundary--

--------------InterScan_NT_MIME_Boundary--
--------------InterScan_NT_MIME_Boundary--

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.