From:                   xavier mas <[EMAIL PROTECTED]>
> I have a file with labels and a small text inside. When this text is 
> different 
> of a pattern text (n, for instance), this label must be deleted, for 
> instance:
> 
> <label>f</label>(more text)<label>n</label>(more text)<label>mpl</label>...
> 
> (labels containing something different to 'n' must be deleted of the string.)
> 
> How can I do this?

Yet another solution

use XML::Rules;

my $parser = XML::Rules->new(
  style => 'filter',
  rules => [
    label => sub {
          my ($tag, $attrs) = @_;
      return if $attrs->{_content} ne 'n'; 
        # skip if the content is not 'n'
      return $tag => $attrs; # print it unmodified
    }
  ]
);

$parser->filter( \*DATA, \$results);

print $results;

__DATA__
<root>
<some x="sdgdfg"><tag>sdfsdf</tag></some>
<label>f</label>(more text)<label>n</label>(more 
text)<label>mpl</label>...
</root>

===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to