This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of DevSecOps Adventures: A Game-Changing Approach with Chocolate, LEGO, and Coaching Games and have Dana Pylayeva on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Quickest way to create objects from XML....

 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am storing the persistent state of thousands of objects for an application in XML. I need to know which of the following 2 methods ould be the fast way to create the objects in memory from the xml representations:

Method #1: Each object is represented in a separate XML text file. The application searches for the object representation based on the name of the XML file. It finds the correct XML file, opens a stream to that file, reads the content, and creates the object in memory using the info in the XML file.

Method #2: Objects are grouped together in a single, massive XML file. Each object is represented by a node or element in the XML file, and each node or element is uniquely identified. The application uses a pull XML parser the read through the file until it reaches the desired node, and uses the information in this node to create the object in memory.

Thanks,

Landon
[ July 06, 2005: Message edited by: Landon Blake ]
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm tempted to say that it would be practical tie, but given that Method #1 doesn't do any parsing (rather slow) until it has the file/object it's looking for and Method #2 would be parsing a large file, I'd guess that Method #1 would be faster, the difference increasing as the number of objects grows.
Disclaimer: Performance depends on a LOT of variables. There's only one way to be sure: Read Java Platform Performance, write both schemes and test, test, test.
Faster still would be to have some sort of in-order index file of the value you are searching on. You could do a binary search of the file using RandomAccessFile. Associated with the index could either a file name or an index into the huge file. Doing a linear search of anything more than a few values will be a big performance drain (see Disclaimer, above).
 
When evil is afoot and you don't have any arms you gotta be hip and do the legwork, but always kick some ... tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic