Readers: 15
![]() |
![]() |
6 entries, 1 page |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<Batch>
<Bescheinigung>
<Mandant>
.
.
</Mandant>
<Empfaenger>
<PersId>4444</PersId>
<Adresse>
<Name>Mustermann</Name>
<Vorname>Hans</Vorname>
<Strasse>Musterweg 4</Strasse>
<PLZ>4711</PLZ>
<Ort>Musterhausen</Ort>
</Adresse>
</Empfaenger>
<Vertragsinformation>
<Vertraege _camvt="array">
<Vertrag vertrag="4711">
<Art>keine Ahnung</Art>
<ErhalteneZulagen _camvt="array">
<ErhalteneZulage beitragsjahr="2002">
<Grundzulage>38,00</Grundzulage>
</ErhalteneZulage>
<ErhalteneZulage beitragsjahr="2003">
.
.
</ErhalteneZulagen>
</Vertrag>
<Vertrag vertrag="4712">
<Art>immer noch keine Ahnung</Art>
.
.
</Vertrag>
.
.
</Vertraege>
</Vertragsinformation>
</Bescheinigung>
<Bescheinigung>
.
.
1
2
3
4
PersId Vertrag Art Beitragsjahr Grundzulage
4444 4711 keine Ahnung 2002 38
2003
4712 usw.
1
2
3
BAUMSTRUCT_1 = /Batch/Bescheinigung/Empfaenger
BAUMSTRUCT_2 = /Batch/Bescheinigung/Empfaenger/Adresse
.
1
2
3
4
5
6
7
8
9
10
11
12
my $baum1 = $props->getProperty("BAUMSTRUCT_1");
my $baum2 = $props->getProperty("BAUMSTRUCT_2");
my $baum3 = $props->getProperty("BAUMSTRUCT_3");
my $baum4 = $props->getProperty("BAUMSTRUCT_4");
my $twig = new XML::Twig( twig_handlers => { $baum1 => \&getBaum1,
$baum2 => \&getBaum2,
$baum3 => \&getBaum3,
$baum4 => \&getBaum4
} );
$twig->parsefile( $opt_datei );
$twig->purge;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
sub getBaum1{
my( $twig, $tree)= @_;
my %hashTree = getTreeField(1);
my $sDummy = "";
$anzCol = 1;
$log->print( Dumper(\%hashTree)."\n" ) if $opt_debug;
foreach my $item ( sort keys %hashTree ){
if( defined($tree->first_child( $hashTree{$item} ))){
my $treeChild = $tree->first_child( $hashTree{$item} );
my $treetext = join '', map { $_->text if( $_->is_text || (exists $_->{'ent'})) } $treeChild->children;
$log->print($item.": ".$treetext."\n" ) if $opt_debug;
$sDummy = encode('iso-8859-1', $treetext );
my @keys = split('_', $item );
$fields{$keys[1]} = $sDummy;
}
$anzCol++;
}
if( $anzCol >= $anzSpalten ){
$log->print( "\n".Dumper(\%fields)."\n" );
&writeFile();
%fields = ();
}
}
perldoc XML:TwigCode: (dl )1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17end_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.
![]() |
![]() |
6 entries, 1 page |