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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |