CoderMan
12th December 2011, 18:20
When reading an XML file, which of the following methods should I use?
(1) Open the file, .setContent(file), parse it in nested loops where I check tagnames with string comparisons and move along with .nextSibling() and .firstChild().
(2) Construct a tree object starting with the root element and adding child elements as I expect them to appear in the file, open the file, .setContent(file), and BAM the previously contructed element objects (and their attributes) now contain the data I need.
If (2) is advisable I could use sample code for the first few elements... how are lists containing an unkown amount of elements with the same tagname (different attribute values) handled?
(1) Open the file, .setContent(file), parse it in nested loops where I check tagnames with string comparisons and move along with .nextSibling() and .firstChild().
(2) Construct a tree object starting with the root element and adding child elements as I expect them to appear in the file, open the file, .setContent(file), and BAM the previously contructed element objects (and their attributes) now contain the data I need.
If (2) is advisable I could use sample code for the first few elements... how are lists containing an unkown amount of elements with the same tagname (different attribute values) handled?