Cool, glad your problems fixed.

Its easy to make a slow XPath expression that has to trawl the entire
document. Using // in an XPath expression is probably the easiest way to
slow things down :-)

James
-------
http://radio.weblogs.com/0112098/
----- Original Message -----
From: "Bram Huenaerts" <[EMAIL PROTECTED]>
To: "DOM4J-user (E-mail)" <[EMAIL PROTECTED]>
Sent: Thursday, August 29, 2002 8:03 AM
Subject: RE: [dom4j-user] DOMReader related problem (Performace)


> Hi,
>
> sorry, but the problem is already solved.
> After debugging I found out that it was another problem
> The problem was that I used XPath on a big XML Document (>1MB)
> When i used the code below, it was very ,very slow.
>
> <code>
> XPath xpathSelector = DocumentHelper.createXPath("//collection/item[" +
> index + "]");
> java.util.List nodes = xpathSelector.selectNodes(document);
> Element element = (Element) nodes.get(0);
> String item = element.asXML();
> byte[] bytes = item.getBytes();
> ...
> </code>
>
> After changing the XPath to this code, the performance increased.
>
> <code>
> XPath xpathSelector = DocumentHelper.createXPath("/*/item[" + index +
"]");
> </code>
>
> Thanks
>
> -----Original Message-----
> From: James Strachan [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, August 28, 2002 5:13 PM
> To: David Hooker; 'DOM4J-user (E-mail)'
> Subject: Re: [dom4j-user] DOMReader related problem (Performace)
>
>
> From: "David Hooker" <[EMAIL PROTECTED]>
> > How do you cache the parser?
>
> Just like the example I coded below. i.e. by reusing the same SAXReader
> instance in the same thread. Creating a new instance each time results in
a
> new underlying SAX parser, the XMLReader, being created which tends to
> reinitialize the underlying parser each time.
>
> Another approach to using ThreadLocal could be to use an object pool
> implementation.
>
> > e.g. if using the dom4j SAXReader, it can often be useful to use
> > ThreadLocal
> > to pool them by thread. e.g.
> >
> > ThreadLocal pool= new ThreadLocal() {
> >     protected Object initialValue() {
> >         return new SAXReader();
> >     }
> > };
> >
> > ...
> > SAXReader reader = (SAXReader) pool.get();
> > reader.parse( "foo.xml" );
>
>
> James
> -------
> http://radio.weblogs.com/0112098/
>
>
> __________________________________________________
> 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: Jabber - The world's fastest growing
> real-time communications platform! Don't just IM. Build it in!
> http://www.jabber.com/osdn/xim
> _______________________________________________
> dom4j-user mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/dom4j-user
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> dom4j-user mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/dom4j-user
>

__________________________________________________
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:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to