As I said, need to stick with XML::Parser!
Not exactly. You seem to have convinced yourself that 1- you need to only use XML::Parser, 2- the Tree style is the simplest way to get what you want. It seems to me that 1 is false lazyness, and 2 is just misguided.
Learning how to use pure-perl modules, even on a machine where you don't have admin rights, would make it easier for you to write not only this piece of code, but also the next ones.
Your problem seems really adapted to a stream processing, whether it's using XML::Parser or an other module. Your code would be much more resistant to changes in the XML structure in the future: in your example [1]->[4]->[4]->[2] is effectively the hardcoded (and some would say obfuscated) path to your target element. If you don't want to hardcode it, you will end up re-writing code that's already written in the likes of XML::Twig, XML::XPath, XML::Rules... Meanwhile with a stream processing you would just process the firstname element, and leave the rest as is, thus you would be able to apply your code even if the input XML changes, as long as it still includes a firstname element.
That said, it's your code, you do what you want, just realize that you will get more help if you follow the general advice of using a better tool for the task.
In reply to Re^3: Trees in XML
by mirod
in thread Trees in XML
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |