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:
<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!

In reply to How to exclude certain blocks of an XML file using Perl and XML::Parser by kgullekson

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.