in reply to XML::Twig Question

I believe what you are looking for is simplify():

my $string = <<'*END*'; <produtos> <produto> <codigo>I0000949</codigo> <nome>Acucareiro Acril 200g Cromus Acrylic Line</nome> <categoria>SALA DE JANTAR:ACESSORIOS PARA MESA</categoria> <marca>Fabrica da Pedra</marca> <preco></preco> <link>4,99</link> <imagem>http://imgproduto.casaevideo.com.br/jpg/ud-cozin/000094 +9b.jpg</imagem> <parcelamento> <parcelas>12</parcelas> <valor>0,53</valor> </parcelamento> </produto> </produtos> *END* use XML::Twig; my $twig = XML::Twig->new(keep_encoding => "true"); $twig->parse( $string); foreach my $product ($twig->root->children('produto')) { my $data = $product->simplify(); # use Data::Dumper; # print Dumper($data); $data->{nome} =~ s/\s+//g; print "$data->{nome}, parselas: $data->{parcelamento}{parcelas}\n" +; # ...................... }
And please do NOT use foo( "$variable"), the quotes are at best pointless. For strings they force Perl to make a copy, for numbers to convert to a string and for references they cause those to get stringified and become unusable. Just drop quotes around single variables untill you really know you do need them. Which is very very seldom.

If you think you can't explain your problem well enough in English, do what you can and then explain it in your own language. I'm sure there are people here that can translate for you.

Replies are listed 'Best First'.
Re^2: XML::Twig Question
by mvitor (Beadle) on Nov 05, 2007 at 15:34 UTC
    thank you guys, the xml::simple is a soltion for the future,
    the method simplify for this moment. thanks ;)

    Márcio Vitor