<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I'm making something, and need to block out BGCOLOR attribute. The problem
> is, the BGCOLOR could be with or without quotation marks. This is the code
I
> used:
>
> $article =~ s/ bgcolor=("?)(.*?)("?)//gi
>
Here is how I would do it, using SAX with a helper module called
XML::SAX::Machines:
package Skip::BGCOLOR;
use strict;
use XML::SAX::Base;
use vars qw/@ISA/;
@ISA = qw/XML::SAX::Base/;
sub start_element {
my($self, $el) = @_;
for my $property ( keys %{ $el->{Attributes} } ) {
if ($property =~ /BGCOLOR$/i ) {
delete( ${ $el->{Attributes} }{$property} );
}
}
$self->SUPER::start_element( $el ); # forward the element downstream
}
sub xml_decl { }
1;
package main;
use strict;
use XML::SAX::Machines qw/:all/;
my($pipeline) = Pipeline(
'Skip::BGCOLOR' =>
\*STDOUT
);
$pipeline->parse_string( join('', <DATA>) );
print("\n");
__DATA__
<html>
<head>
<title>No BGCOLORs</title>
</head>
<body bgcolor="red">
<h1 bgcolor="white">No BGCOLORs</h1>
<hr width="75%" />
<div BGCOLOR="blue">No BGCOLORs</div>
</body>
</html>
Much cleaner and it guarantees to not fudge up your markup.
Todd W.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]