Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Ex: <c> <dl> ABC CDE add eerwe sdfsdfs erewrwe </dl> </c> Expected Result: <c> <dl> <first>ABC</first><second>CDE</second> <first>add</first><second>eerwe</second> <first>sdfsdfs</first><second>erewrwe</second> </dl> </c> Obtained Result: <c> <dl> <first>ABC</first><second>CDE</second> <first>add</first><second>eerwe</second> <first>sdfsdfs</first><second>erewrwe</second>rwe </dl> </c>
Thanks in advance, -Anonymous user-Code Used: my $t = new XML::Twig( twig_handlers => { "content"=>\&process_root }, pretty_print =>'nice', )->parsefile("$ARGV[0]"); my $say=$t->sprint; print FOUT "$say"; sub process_root { my ($a,$b,$c)=@_; my $bchild; for $bchild ($b->children) { if ($bchild->tag eq 'dl') { $bchild=&dl($a,$bchild); } } return $b; } sub dl { my ($a,$b,$c)=@_; my $bchild; if ($bchild->text) { $bchild->subs_text( qr{(.+?)\t(.+?)\n},'&elt(first=>{},$1)&elt(second=>{},$2)'); } return $b; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: problem using XML Twig
by Roger (Parson) on Sep 29, 2004 at 07:38 UTC | |
by Anonymous Monk on Sep 29, 2004 at 08:25 UTC | |
by Roger (Parson) on Sep 29, 2004 at 11:16 UTC | |
|
Re: problem using XML Twig
by mirod (Canon) on Sep 29, 2004 at 13:24 UTC |