[Roma.pm] xml + tag name
Aldo Calpini
dada at perl.it
Tue Jul 17 03:49:46 PDT 2007
Oha ha scritto:
> se ricordo bene, ritorna una struttura di hash di hash.
> in perl, un hash puo' esser usato come array
>
> quini se $ref contiene il nodo che ti interessa
> dovresti ottenere il nome del nodo come $ref[0]
>
> vado a memoria, non ho il modulo installato dove sono ora
>
stai fuori come uno zerbino, oha. un hash NON può essere usato come
array e $ref[0] è tutt'altra cosa. per ricavare i tag usando XML::Simple
puoi basarti sull'esempio che trovi qua sotto.
cheers,
Aldo
use XML::Simple;
my $data;
{ undef $/; $data = <DATA>; }
my $x = XMLin( $data, KeepRoot => 1 );
walktree(0, $x);
sub walktree {
my($level, $node) = @_;
foreach my $tag (keys %$node) {
print " " x $level, "$tag\n";
walktree($level+1, $node->{$tag}) if ref($node->{$tag}) eq 'HASH';
}
}
__DATA__
<a>
<b>
<c />
<d />
</b>
</a>
More information about the Roma
mailing list