If you have no control over your XML format and you are stuck using XML::Parser, then you can igonre the rest of this post. Otherwise, please consider the following.

While I'm sure what you have is valid XML, it's too bad it isn't structured differently. Had your CustomDimensionName and customBucketValueString elements been children of customBucket, you could have filtered your information as follows:

use strict; use warnings; use XML::Twig; my $xmlStr = <<XML; <foo> <customBucket> <customDimensionName>Strategy</customDimensionName> <customBucketValueString>Test1</customBucketValueString> </customBucket> <customBucket> <customDimensionName>SubStrategy</customDimensionName> <customBucketValueString>Test2</customBucketValueString> </customBucket> </foo> XML my $t = XML::Twig->new(); $t->parse($xmlStr); for my $bucket ($t->root()->children('customBucket')) { if ($bucket->first_child('customDimensionName')->text() ne 'Strate +gy') { print 'customDimensionName ' , $bucket->first_child('custom +DimensionName' )->text(), "\n"; print 'customBucketValueString ', $bucket->first_child('custom +BucketValueString')->text(), "\n"; } } __END__ customDimensionName SubStrategy customBucketValueString Test2

I abandoned using XML::Parser once I discovered XML::Twig, which I find to be easier to understand and use.


In reply to Re: How to exclude certain blocks of an XML file using Perl and XML::Parser by toolic
in thread 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.