Jump to content

Xml File Change And Reuse - Speed


global.user

Recommended Posts

Say I want to change an XML file then use it afterwards.Is it faster to load it, change it (not necessarily with DOM), write back to file, then open it as DOM Doc...Or to load, change it, convert to readable string and convert to DOM document?I am wanting to do a change that involves more than what the DOM offers...

Link to comment
Share on other sites

What can be the thing that you want to do that can't be done with DOM? If the problem is selecting some odd combination of nodes, DOMXPath will do it. All manipulations on DOM that you may want to do are doable in DOM...Anyway... both approaches you suggest have pros and cons, but I'd go for the "string in memory" (i.e. your second approach).In the first approach you have:1. Loading a file2. Parsing text into... some form3. Manipulation4. Serialization into text5. Saving a file6. Loading a file7. Parsing text into DOM8. Manipulation9. Serializing into text...And in the second, 5 and 6 are gone. However, the con of the second approach is that you need to keep the serialized XML (i.e. the "text") into memory in addition to its DOM. If you can perform the serialization within loadXML() itself, you'll eliminate that part. Also, if you plan to reuse the file as it appears before the DOM parsing it will be more efficient if you save it and load it. Serialization is far more expensive than file loading.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...