kgullekson has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
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!
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:
<customBucket></customBucket> <customDimensionName>Strategy</customDimensionName> <customBucketValueString>Test1</customBucketValueString> <customBucketEnd></customBucketEnd> <customBucket></customBucket> <customDimensionName>SubStrategy</customDimensionName> <customBucketValueString>Test2</customBucketValueString> <customBucketEnd></customBucketEnd>
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!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: How to exclude certain blocks of an XML file using Perl and XML::Parser
by toolic (Bishop) on Feb 12, 2009 at 23:15 UTC | |
by kgullekson (Initiate) on Feb 12, 2009 at 23:28 UTC | |
by mirod (Canon) on Feb 13, 2009 at 08:46 UTC | |
Re: How to exclude certain blocks of an XML file using Perl and XML::Parser
by GrandFather (Saint) on Feb 12, 2009 at 23:21 UTC | |
Re: How to exclude certain blocks of an XML file using Perl and XML::Parser
by mirod (Canon) on Feb 13, 2009 at 09:04 UTC |
Back to
Seekers of Perl Wisdom