Thread Verständnis-Problem XML-Twig (5 answers)
Opened by nyjo at 2008-02-20 08:55

renee
 2008-02-20 11:07
#106135 #106135
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
perldoc XML:Twig
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
end_tag_handlers 
A hash { expression = \&handler}>. Sets element handlers that are called when the element is closed (at the end of the XML::Parser End handler). The handlers are called with 2 params: the twig and the tag of the element.

twig_handlers are called when an element is completely parsed, so why have this redundant option? There is only one use for end_tag_handlers: when using the twig_roots option, to trigger a handler for an element outside the roots. It is for example very useful to number titles in a document using nested sections:

my @no= (0);
my $no;
my $t= XML::Twig->new(
start_tag_handlers =>
{ section => sub { $no[$#no]++; $no= join '.', @no; push @no, 0; } },
twig_roots =>
{ title => sub { $_[1]->prefix( $no); $_[1]->print; } },
end_tag_handlers => { section => sub { pop @no; } },
twig_print_outside_roots => 1
);
$t->parsefile( $file);
Using the end_tag_handlers argument without twig_roots will result in an error.


Ich habe hier leider kein XML::Twig, so dass ich es nicht ausprobieren kann...
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/

View full thread Verständnis-Problem XML-Twig