#!perl
use HTML::Parser;
use HTML::Stream;
# see HTML::Stream documentation for how to output to a scalar
$output = new HTML::Stream \*STDOUT;
# inside FIELDs, ignore stuff that looks like tags
$insidefield = 0;
my $p = HTML::Parser->new
(
xml_mode => 1,
start_h =>
[sub {
my ($tagname, $attr,$text) = @_;
if ($insidefield) {$output->text($text);}
else {$output->tag($tagname, %$attr);}
if ($tagname eq 'FIELD') {$insidefield = 1;}
}, "tagname, attr,text"],
text_h =>
[sub {
my ($text) = @_;
$output->text($text);
}, "dtext"],
end_h =>
[sub {
my ($tagname, $text) = @_;
if ($tagname eq 'FIELD') {$insidefield = 0;}
if ($insidefield) {$output->text($text);}
else {$output->tag("_$tagname");}
}, "tagname, text"],
);
$p->parse_file(\*DATA);
__END__
name
pass
pass&word
pass>word
pass&word
pass&word
paord
do_what