سؤال

I have been reading up on xml reading and writing using SAX, STAX, and dom. My problem is that even after reading the advantages and disadvantages I am still not sure on which would be the best for my purposes - although DOM does appear to be the simplest, I will be running this program on a very weak server with little memory so I am keen to make the program more efficient if possible. High demand on the server would also push the need for efficiency.

Here's what I need:

  1. Simply read through an xml document pulling different data from it. At this point I had decided that SAX parser would be all I need as apparently it is the fastest?

  2. However, I also need to be able to generate xml documents. At this point I thought great - STAX is what I should use as it appears to have similar functionality to SAX however allows the generation of xml code.

  3. Most tricky is that I need to be able to read through an existing xml document and edit specific parts of it i.e. the characters in between start and end tags. DOM looks to be the best to do this however everyone says that DOM uses a lot of resources and is quite slow. So is this possible with Stax?

I would like to use dom but am concerned with memory and processor usage, etc.

Can I ask how much more resources it would use when compared to STax in a real world example? The xml files are not likely to be large and I would only need to make a few reads and writes. That is, the program is a game and at the beginning I need to load information on a player and at the end, locate the xml info on the player and make amendments based on the players performance as quick as possible.

Thanks a lot for any answers/advice

هل كانت مفيدة؟

المحلول

Using Sax As you want to modify XML this is not going to help you

Using DOM Since you care about memory(efficiency) this is not going to work

Using Stax This is what helps your concerns. You have also pointed on it. How to modify XML using Stax is discussed here

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top