From: James Britt Date: 2005-06-24T14:10:24+09:00 Subject: Re: REXML Optimization Bucco wrote: > Just to help me complete the learning process, I wish to pose the > question to the group: Is there a better way to do this, and is there > more optimization I can do to my code? The DOM is not a database, and it shows. XPath queries can get real slow as the document size grows. Suggestion: Read and parse the XML once, and store it internally in a format better suited for queries. XML is great for all sorts of things, particularly for inter-app data exchange, but once the data is inside your system that value drops. So, if the code is mainly concerned with executing queries and such, slurp in the XML and stash it in some optimized internal structure. Maybe use Madeleine for in-memory storage and queries. If need be, add code to serialize the data back to XML for persistence when the app is shut down. Try to compute the start-up cost of the parsing and restructuring and indexing the data right up front, versus the cost of running XPath calls over and over. See if it gains you anything. James -- http://www.ruby-doc.org - The Ruby Documentation Site http://www.rubyxml.com - News, Articles, and Listings for Ruby & XML http://www.rubystuff.com - The Ruby Store for Ruby Stuff http://www.jamesbritt.com - Playing with Better Toys