Here is my scenario:
-
I have an XML file where various attributes (TextBox, CheckBox etc) of an HTML form are specified. (this is because, if the form changes later, the user only edits the XML file)
-
Now, I need to read the XML file and render the presentation accordingly.
So, should I:
-
Read the XML file everytime I need to render the presentation, OR
-
Read the file once during initialization of the app and save it some where in the memory? If yes, then how?
File is very small: 2.5KB, 60lines
It probably makes little difference to your code whether you read the XML file once or multiple times. (It affects performance, but that’s not the real issue. And you should be able to switch between the two approaches with little effort.)
The real issue is how your rendering code accesses the information (in a sense, metadata) represented by the XML. You have a number of alternatives. For example:
Which is best rather depends on the complexity of your XML (or more precisely, its schema), and how much of your rendering code needs to “touch” the metadata. Generally speaking, the greater the complexity and the more your code depends on it, the more you need to move away from using the DOM directly.