use XML::Simple;
use XML::TokeParser;
use Data::Dumper 'DumperX';
my $ARGH = q{podmaster};
print "\n\n0000000000000000000000000000000000000000000000000000000\n\n";
print 'warn DumperX teh_xml_to_hashref($ARGH);'."\n";
eval'warn DumperX teh_xml_to_hashref($ARGH);';
warn "oh $! and $@ " if $@;
print 'warn DumperX teh_xml_to_hashref2($ARGH);'."\n";
eval'warn DumperX teh_xml_to_hashref2($ARGH);';
warn "oh $! and $@ " if $@;
print "\n\n111111111111111111111111111111111111111111111111111111111\n\n";
print 'warn DumperX teh_xml_to_hashref(\$ARGH);'."\n";
eval'warn DumperX teh_xml_to_hashref(\$ARGH);';
warn "oh boy $! and $@ " if $@;
print 'warn DumperX teh_xml_to_hashref2(\$ARGH);'."\n";
eval'warn DumperX teh_xml_to_hashref2(\$ARGH);';
warn "oh boy $! and $@ " if $@;
print "\n\n2222222222222222222222222222222222222222222222222222222222222\n\n";
print 'warn DumperX teh_xml_to_hashref(${\$ARGH});'."\n";
eval'warn DumperX teh_xml_to_hashref(${\$ARGH});';
warn "damn $! and $@ " if $@;
print 'warn DumperX teh_xml_to_hashref2(${\$ARGH});'."\n";
eval'warn DumperX teh_xml_to_hashref2(${\$ARGH});';
warn "damn $! and $@ " if $@;
print "\n\n333333333333333333333333333333333333333333333333333333333333\n\n";
my %DBHASH = ( 1000 => $ARGH );
warn DumperX \%DBHASH;
print 'warn DumperX teh_xml_to_hashref(\$DBHASH{1000});'."\n";
eval'warn DumperX teh_xml_to_hashref(\$DBHASH{1000});';
warn "damn $! and $@ " if $@;
print 'warn DumperX teh_xml_to_hashref2(\$DBHASH{1000});'."\n";
eval'warn DumperX teh_xml_to_hashref2(\$DBHASH{1000});';
warn "damn $! and $@ " if $@;
print "\n\n444444444444444444444444444444444444444444444444444444444444444444\n\n";
my $refa = \$DBHASH{'1000'};
warn $refa. ' refa ';
warn $$refa. ' $refa ';
print 'warn DumperX teh_xml_to_hashref($refa);'."\n";
eval'warn DumperX teh_xml_to_hashref($refa);';
warn "damn $! and $@ " if $@;
print 'warn DumperX teh_xml_to_hashref2($refa);'."\n";
eval'warn DumperX teh_xml_to_hashref2($refa);';
warn "damn $! and $@ " if $@;
sub teh_xml_to_hashref {
my $fref = shift;
return XMLin($fref);
}
sub teh_xml_to_hashref2 {
my $htmlref = shift;
my $t;
my $p = XML::TokeParser->new($htmlref, ErrorContext => 3 ) or die $!;
my %N=();
$t = $p->get_tag('NODE');
$N{'reputation'} = $t->[1]->{'reputation'};
$N{'createtime'} = $t->[1]->{'createtime'};
$N{'id'} = $t->[1]->{'id'};
$t = $p->get_trimmed_text('/NODE') or die $!;
$N{'content'} = $t;
return \%N;
}
__END__
F:\dev\XmlPimp\crazydev\XmlPimp>perl xml.t
0000000000000000000000000000000000000000000000000000000
warn DumperX teh_xml_to_hashref($ARGH);
$VAR1 = {
'reputation' => '0',
'content' => 'podmaster',
'createtime' => '2001-08-24 08:01:08',
'id' => '107642'
};
warn DumperX teh_xml_to_hashref2($ARGH);
oh Invalid argument and Invalid argument at xml.t line 62.
at xml.t line 12.
111111111111111111111111111111111111111111111111111111111
warn DumperX teh_xml_to_hashref(\$ARGH);
oh boy and
not well-formed at line 1, column 6, byte 6 at c:/Perl/site/lib/XML/Parser.pm li
ne 168
at xml.t line 17.
warn DumperX teh_xml_to_hashref2(\$ARGH);
$VAR1 = {
'reputation' => '0',
'content' => 'podmaster',
'createtime' => '2001-08-24 08:01:08',
'id' => '107642'
};
2222222222222222222222222222222222222222222222222222222222222
warn DumperX teh_xml_to_hashref(${\$ARGH});
$VAR1 = {
'reputation' => '0',
'content' => 'podmaster',
'createtime' => '2001-08-24 08:01:08',
'id' => '107642'
};
warn DumperX teh_xml_to_hashref2(${\$ARGH});
damn Invalid argument and Invalid argument at xml.t line 62.
at xml.t line 29.
333333333333333333333333333333333333333333333333333333333333
$VAR1 = {
'1000' => 'podmaster'
};
warn DumperX teh_xml_to_hashref(\$DBHASH{1000});
damn No such file or directory and
not well-formed at line 1, column 6, byte 6 at c:/Perl/site/lib/XML/Parser.pm li
ne 168
at xml.t line 36.
warn DumperX teh_xml_to_hashref2(\$DBHASH{1000});
$VAR1 = {
'reputation' => '0',
'content' => 'podmaster',
'createtime' => '2001-08-24 08:01:08',
'id' => '107642'
};
444444444444444444444444444444444444444444444444444444444444444444
SCALAR(0x1abf060) refa at xml.t line 44.
podmaster $refa at xml.t line 45.
warn DumperX teh_xml_to_hashref($refa);
damn No such file or directory and
not well-formed at line 1, column 6, byte 6 at c:/Perl/site/lib/XML/Parser.pm li
ne 168
at xml.t line 48.
warn DumperX teh_xml_to_hashref2($refa);
$VAR1 = {
'reputation' => '0',
'content' => 'podmaster',
'createtime' => '2001-08-24 08:01:08',
'id' => '107642'
};
F:\dev\XmlPimp\crazydev\XmlPimp>