<HTML><BODY style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; "><BR><DIV><DIV>On Apr 30, 2007, at 2:27 PM, roan Brasil wrote:</DIV><BR class="Apple-interchange-newline"><BLOCKQUOTE type="cite">Olá Galera,<BR><BR>Estou precisando de uma ajudinha. Eu tenho um padrão de desenvolvimento já usado aqui  simples para coletar informações do XML usando XML Twig. Então preciso coletar essas informações nesse XML  no link-&gt; <A href="http://www.rumo.com.br/sistema/XMLProdutos.asp?IDLoja=6928&Texto=&IDProduto=&IDCategoria=&ExibeDescricao=1&origem=jacotei&est=&Mult">http://www.rumo.com.br/sistema/XMLProdutos.asp?IDLoja=6928&amp;Texto=&amp;IDProduto=&amp;IDCategoria=&amp;ExibeDescricao=1&amp;origem=jacotei&amp;est=&amp;Mult </A><BR><BR>Sendo que a string resultante dessa requisição é a <SPAN style="font-weight: bold; color: rgb(255, 102, 102);">variavel $string</SPAN>;<BR>Estou usando XML::Twig da seguinte forma:<BR><BR> <SPAN style="font-weight: bold;"> my $twig = XML::Twig-&gt;new(keep_encoding =&gt; "true");</SPAN><BR style="font-weight: bold;"><SPAN style="font-weight: bold;">    $twig-&gt;parse("$string");</SPAN><BR style="font-weight: bold;"><SPAN style="font-weight: bold;">     foreach my $product ($twig-&gt;root-&gt;children('produto')) {</SPAN><BR style="font-weight: bold;"><SPAN style="font-weight: bold;">        my $sibling = $product-&gt;first_child();</SPAN><BR style="font-weight: bold;"> <SPAN style="font-weight: bold;">        my %produto;</SPAN><BR style="font-weight: bold;"><SPAN style="font-weight: bold;">        my @nodes;</SPAN><BR style="font-weight: bold;"><SPAN style="font-weight: bold;">        do { </SPAN><BR style="font-weight: bold;"><SPAN style="font-weight: bold;">            $produto{$sibling-&gt;tag()} = $sibling-&gt;child_text();</SPAN><BR style="font-weight: bold;"><SPAN style="font-weight: bold;">        } while($sibling = $sibling-&gt;next_sibling()); </SPAN><BR><BR>Só que preciso pegar o valor da tag <SPAN style="color: rgb(51, 51, 255);">&lt;descritor nome="Peso líquido:"&gt;</SPAN><SPAN style="font-weight: bold; color: rgb(51, 51, 255);">VALOR</SPAN><SPAN style="color: rgb(51, 51, 255);"> &lt;/descritor&gt;</SPAN>.<BR>Reparando bem existe <SPAN style="font-weight: bold;">outra tag  descritor</SPAN> onde o atributo nome tem valor <SPAN style="font-weight: bold;">DIMENSÕES</SPAN>. <BR>Alguém pode me ajudar a pegar esse <SPAN style="font-weight: bold; color: rgb(51, 102, 255);">VALOR</SPAN>?<BR><BR clear="all"></BLOCKQUOTE><BR></DIV><DIV>Não olhei o seu documento, o trabalho é seu e vou deixar que o faça. Aqui está um exemplo de como eu faria -da forma mais didática que eu encontrei:</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>--code--</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>#!perl;</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>use strict;</DIV><DIV>use warnings;</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>use XML::Twig;</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>my $twig = XML::Twig-&gt;new( keep_encoding =&gt; 1 );</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>$twig-&gt;parse( \*DATA );</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>my @produtos = $twig-&gt;get_xpath(q{//produto});</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>for my $p (@produtos) {</DIV><DIV>    if ( my ($d) = $p-&gt;get_xpath(q{descritor}) ) {</DIV><DIV>        if ( $d-&gt;att('nome') eq 'Peso liquido:' ) {</DIV><DIV>            print $d-&gt;string_value, $/;</DIV><DIV>        }</DIV><DIV>    }</DIV><DIV>}</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>__DATA__</DIV><DIV>&lt;raiz&gt;</DIV><DIV>    &lt;produto&gt;</DIV><DIV>        &lt;descritor nome="Peso liquido:"&gt;VALOR&lt;/descritor&gt;</DIV><DIV>    &lt;/produto&gt;</DIV><DIV>    &lt;produto&gt;</DIV><DIV>        &lt;descritor nome="Peso liquido:"&gt;VALOR1&lt;/descritor&gt;</DIV><DIV>        &lt;descritor nome="Peso bruto:"&gt;VALOR2&lt;/descritor&gt;</DIV><DIV>    &lt;/produto&gt;</DIV><DIV>&lt;/raiz&gt;</DIV><DIV><BR class="khtml-block-placeholder"></DIV>--/code--<DIV><BR class="khtml-block-placeholder"></DIV><DIV>Se você estiver interessado apenas nas tags 'descritor' de nome 'nome' com valor 'Peso liquido:' podes procurar os elementos através de uma expressão xpath do tipo '//descritor[@nome="Peso liquido:"]'.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Boa sorte!</DIV><DIV><BR><DIV> <SPAN class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Lucida Grande; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><DIV>--</DIV><DIV>Igor Sutton</DIV><DIV><A href="mailto:igor.sutton@gmail.com">igor.sutton@gmail.com</A></DIV><DIV><BR class="khtml-block-placeholder"></DIV><BR class="Apple-interchange-newline"></SPAN> </DIV><BR></DIV></BODY></HTML>