I have one query regarding XML. I have a XML file which is having few nodes at same level, like :
There is no root node above this level. this is how the data reaches to my application. I wanted to know the best optimal way to traverse all the A nodes, without going through B nodes. The current implementation which I have is to iterate all the nodes, then do element.getName().equals("A") and so on.. but the processing in this is too much, as I have this node, then I have to process it's many child nodes and get many attributes from these node and the child nodes.
I am not able to find a better logic for this. Please let me know what if what I am missing here..
thanks for replying. well, i had thought about getting elements by tag name, did not try it. i have some 5000 nodes in the format which i have given. within each A node and B node, there will be some child nodes which will vary based on some conditions, I am looking at the most optimal way to traverse all the A nodes and it's child nodes once, without repeating anything or getting messed up in iteration.
i will start working on these soon, just wanted to plan out how i will be going through this task.
s ravi chandran wrote:I am looking at the most optimal way to traverse all the A nodes and it's child nodes once, without repeating anything or getting messed up in iteration.
Well, you only have 5000 nodes so it's a pretty small file. So it isn't worth spending any time looking for the "most optimal" way. Just pick a reasonable way and carry on with that.
Thanks for replying. Well, I have to show a quick demo to some client. So, i will be taking 5000 node A and some 3000 node B mixed up. But the actual client data may have millions of nodes of various types. so, optimization is one thing which I want to stress before designing, so that my implementation won't need to be changed in the later stage.
s ravi chandran wrote:...so, optimization is one thing which I want to stress before designing, so that my implementation won't need to be changed in the later stage...
In which case, optimization is the LAST thing (quite literally) you want to be doing, and certainly not before designing. Furthermore, if you design your demo correctly, you will be able to change the implementation to add optimization quite happily.
Michael A. Jackson wrote:The First Rule of Program Optimization: Don't do it.
The Second Rule of Program Optimization (for experts only!): Don't do it yet.
If you try to please everybody, your progress is limited by the noisiest fool. And this tiny ad: