|Keep It Simple, Stupid|
How to exclude certain blocks of an XML file using Perl and XML::Parserby kgullekson (Initiate)
|on Feb 12, 2009 at 19:59 UTC||Need Help??|
kgullekson has asked for the
wisdom of the Perl Monks concerning the following question:
I've got basic Perl skills and am even worse at understanding the XML::Parser so hope someone can help.
I've got an xml file that has lines like:
My Perl script currently uses Start, End and Char handlers. The Start and End handlers just do things like indent stuff etc and the Char handler manipulates tag names and values in certain cases. I need to be able to suppress printing the lines starting with the customBucket tag and ending with the customBucketEnd tag based on the value of the customDimensionName. So, for example, if the value of CustomDimensionName is "Strategy", I don't want to print lines 1-4 in my example above.
I'm thinking that somehow this has to be done in the Start handler but I can't see a way of knowing what's following the customBucket element without actually getting into the Char handler but by then, I've already printed out my customBucket line.
I was thinking that I could use some sort of stack to push each element on and then only pop off when I knew the 4 lines were something I wanted to print. This just seemed messy.
The script I have currently does a lot of other stuff so I can't really change the functionality too much without risking messing up something else.
Apologies if I've not used the right terminology. Hope the above makes sense.
Thanks for any help!