Thread Problem beim auslesen einer XML-Datei mit XML-Twig (3 answers)
Opened by nyjo at 2007-10-24 12:37

renee
 2007-10-25 13:30
#101312 #101312
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Code (perl): (dl )
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
#!/usr/bin/perl

use strict;
use warnings;
use XML::Twig;
use Data::Dumper;

my $content = do{ local $/; <DATA> };
my $twig = new XML::Twig( twig_handlers => {  'NatuerlichePerson'   => \&getPerson,} );

$twig->parse( $content );

sub getPerson{ 
  my( $twig, $pers)= @_;
  
  my $child = $pers->first_child( 'geburtsdatum' );
  #$child->cut_children;
  my $text = join '', map { $_->text if( $_->is_text || (exists $_->{'ent'})) } $child->children;
  print $text;
}

__DATA__
<NatuerlichePerson cx:dt="null" cx:ct="struct" _name="NatuerlichePerson">
                    <geburtsdatum _name="geburtsdatum">19.05.1949<cx:attrib>
                            <_index cx:dt="int">6</_index>
                        </cx:attrib>
                    </geburtsdatum>
                    </NatuerlichePerson>


ab Version 3.28 gibt's auch die Methode "text_only", was das join '',... macht...
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 Problem beim auslesen einer XML-Datei mit XML-Twig