<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2900.2912" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Obrigado André! </FONT></DIV>
<DIV><FONT face=Arial size=2>Vou fazer alguns testes aqui e
retorno..</FONT></DIV>
<DIV><FONT face=Arial size=2>Marcio.</FONT></DIV>
<BLOCKQUOTE
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV
style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B>
<A title=andregarciacarneiro@gmail.com
href="mailto:andregarciacarneiro@gmail.com">Andre Carneiro</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=saopaulo-pm@mail.pm.org
href="mailto:saopaulo-pm@mail.pm.org">saopaulo-pm@mail.pm.org</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Friday, December 04, 2009 3:26
PM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> Re: [SP-pm] XML::Simple</DIV>
<DIV><BR></DIV>Grego é?? Blz! Vou tentar traduzir um pouquinho
então...<BR><BR><code><BR>use strict;<BR>use XML::Simple;<BR>use
Data::Dumper; #Isso vai ajudar vc a entender o que o XML::Simple vai trazer e
como vai trazer.<BR><BR>my $string = '<?xml version="1.0" encoding="utf-8"
?><BR>
<FONT face=Arial size=2><soap:Envelope xmlns:xsi="<A
href="http://www.w3.org/2001/XMLSchema-instance"
target=_blank>http://www.w3.org/2001/XMLSchema-instance</A>" xmlns:xsd="<A
href="http://www.w3.org/2001/XMLSchema"
target=_blank>http://www.w3.org/2001/XMLSchema</A>" xmlns:soap="<A
href="http://schemas.xmlsoap.org/soap/envelope/"
target=_blank>http://schemas.xmlsoap.org/soap/envelope/</A>"><BR>
<soap:Header><BR> <AuthHeader
xmlns="vscws"><BR>
<distriID>XXXX</distriID><BR>
<password>XXXXXX</password><BR>
</AuthHeader><BR> </soap:Header><BR>
<soap:Body><BR> <getUserTransactions
xmlns="vscws"><BR>
<controlNumber>XXXXXX</controlNumber><BR>
<transactionType></transactionType><BR>
<dateFrom>2009-11-10</dateFrom><BR>
<dateTo>2009-11-30</dateTo><BR>
</getUserTransactions><BR>
</soap:Body><BR></soap:Envelope>';</FONT>
<PRE><FONT size=4><BR> my $ref = undef;<BR> my $obj = XML::Simple->new();<BR><BR> #Tratando possivel erro de parsing<BR> eval{$ref = $obj->XMLin($string);};#Isso transforma o XML em uma estrutura de dados em forma de hashes e arrays... <BR>
if($@){<BR> print "\nNao foi possivel fazer o parsing: $@\n";<BR> }else{<BR><BR> print Dumper $ref; #Isso mostra a estrutura de dados gerada pelo parsing.<BR> my $xml = XMLout($ref);#Isso converte a estrutura de dados armazenada em $ref para XML novamente. <BR>
#Não sei se tem muito sentido isso para você, mas enfim...<BR> }<BR></FONT></PRE>__END__<BR><BR></code><BR><BR><BR>Quando
executar esse script, vai ver algo do tipo: <BR><BR><BR>$VAR1 =
{<BR> 'xmlns:xsi' =>
'<A
href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</A>',<BR>
'soap:Header' =>
{<BR>
'AuthHeader' =>
{<BR>
'xmlns' =>
'vscws',<BR>
'password' =>
'XXXXXX',<BR>
'distriID' =>
'XXXX'<BR>
}<BR>
},<BR> 'soap:Body' =>
{<BR>
'getUserTransactions' =>
{<BR>
'xmlns' =>
'vscws',<BR>
'transactionType' =>
{},<BR>
'dateFrom' =>
'2009-11-10',<BR>
'dateTo' =>
'2009-11-30',<BR>
'controlNumber' =>
'XXXXXX'<BR>
}<BR>
},<BR> 'xmlns:xsd' =>
'<A
href="http://www.w3.org/2001/XMLSchema">http://www.w3.org/2001/XMLSchema</A>',<BR>
'xmlns:soap' => '<A
href="http://schemas.xmlsoap.org/soap/envelope/">http://schemas.xmlsoap.org/soap/envelope/</A>'<BR>
};<BR><BR>Aí é só acessar via perl o que você quer. Por exemplo, vamos
capturar
'getUserTransactions'<BR><BR><code><BR><BR>
my $getUserTransaction =
$xml->{soap.Body}->{getUsertTransaction};<BR><BR></code><BR><BR><BR>Melhorou?<BR><BR>
<DIV class=gmail_quote>2009/12/4 Daniel de Oliveira Mantovani <SPAN
dir=ltr><<A
href="mailto:daniel.oliveira.mantovani@gmail.com">daniel.oliveira.mantovani@gmail.com</A>></SPAN><BR>
<BLOCKQUOTE class=gmail_quote
style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">2009/12/4
Marcio Mello <<A
href="mailto:marcio@modapoint.com.br">marcio@modapoint.com.br</A>>:<BR>
<DIV>
<DIV></DIV>
<DIV class=h5>> Olá à todos,<BR>> Não conheço bem o módulo
XML::Simple e não sei como traduzir os dados<BR>>
corretamente.<BR>> Se alguém puder ajudar, fico grato..<BR>><BR>> A
resposta que recebo do servidor está aqui e o código está
abaixo:<BR>><BR>>
===========================================================<BR>> $VAR1 =
{ 'xmlns:xsi' => '<A href="http://www.w3.org/2001/XMLSchema-instance"
target=_blank>http://www.w3.org/2001/XMLSchema-instance</A>',<BR>>
'soap:Body' => { 'getUserTransactionsResponse' => { 'xmlns' =>
'vscws',<BR>> 'getUserTransactionsResult' => { 'VSC' => { 'xmlns'
=> '',<BR>> 'userTransactions' => [ { 'Time' => '1:00', 'Limit'
=> '5', 'DNIS' =><BR>> '56012', 'destinationDescription' =>
"Brasil - S\x{e3}o Paulo - \x{c1}rea 11<BR>> - Celular", 'Income' =>
'0.0000', 'controlNumber' => '2414568', 'ANI' =><BR>> '1145822125',
'DestinationNumber' => '551199117099', 'Balance' => '-44.024',<BR>>
'startTime' => '2009-11-27 17:28:45', 'Cost' => '0.89',<BR>>
'transactionDescription' => 'Termination', 'billing' =>
'Limited',<BR>> 'RealTime' => '0:22' }, { 'Time' => '1:00', 'Limit'
=> '5', 'DNIS' =><BR>> '56012', 'destinationDescription' =>
'Brasil - Roc', 'Income' => '0.0000',<BR>> 'controlNumber' =>
'2414568', 'ANI' => '1145822125', 'DestinationNumber' =><BR>>
'551145215888', 'Balance' => '-44.314', 'startTime' =>
'2009-11-27<BR>> 17:25:45', 'Cost' => '0.29', 'transactionDescription'
=> 'Termination',<BR>> 'billing' => 'Limited', 'RealTime' =>
'0:19' }, { 'Time' => '1:00', 'Limit'<BR>> => '5', 'DNIS' =>
'56012', 'destinationDescription' => 'Brasil - Roc',<BR>> 'Income'
=> '0.0000', 'controlNumber' => '2414568', 'ANI' =>
'1145822125',<BR>> 'DestinationNumber' => '551145215888', 'Balance'
=> '-44.604', 'startTime'<BR>> => '2009-11-27 17:16:30', 'Cost'
=> '0.29', 'transactionDescription' =><BR>> 'Termination',
'billing' => 'Limited', 'RealTime' => '0:24' }, { 'Time' =><BR>>
'1:00', 'Limit' => '5', 'DNIS' => '56012', 'destinationDescription'
=><BR>> 'Brasil -', 'Income' => '0.0000', 'controlNumber' =>
'2414568', 'ANI' =><BR>> '1145822125', 'DestinationNumber' =>
'551164545504', 'Balance' => '-45.494',<BR>> 'startTime' =>
'2009-11-27 17:06:44', 'Cost' => '0.89',<BR>> 'transactionDescription'
=> 'Termination', 'billing' => 'Limited',<BR>> 'RealTime' =>
'0:12' }, { 'Time' => '1:48', 'Limit' => '5', 'DNIS' =><BR>>
'56012', 'destinationDescription' => 'Brasil - Roc', 'Income' =>
'0.0000',<BR>> 'controlNumber' => '2414568', 'ANI' => '1130337016',
'DestinationNumber' =><BR>> '551130337005', 'Balance' => '-46.016',
'startTime' => '2009-11-27<BR>> 12:19:22', 'Cost' => '0.522',
'transactionDescription' => 'Termination',<BR>> 'billing' =>
'Limited', 'RealTime' => '1:43' }, { 'Time' => '1:00', 'Limit'<BR>>
=> '5', 'DNIS' => '56012', 'destinationDescription' => "Brasil -
S\x{e3}o<BR>> Paulo - \x{c1}rea 11 - Celular", 'Income' => '0.0000',
'controlNumber' =><BR>> '2414568', 'ANI' => '1130337016',
'DestinationNumber' => '551199117099',<BR>> 'Balance' => '-46.906',
'startTime' => '2009-11-27 12:20:28', 'Cost' =><BR>> '0.89',
'transactionDescription' => 'Termination', 'billing' =>
'Limited',<BR>> 'RealTime' => '0:13' }, { 'Time' => '1:00', 'Limit'
=> '5', 'DNIS' =><BR>> '56012', 'destinationDescription' =>
"Brasil - S\x{e3}o Paulo - \x{c1}rea 11<BR>> - Celular", 'Income' =>
'0.0000', 'controlNumber' => '2414568', 'ANI' =><BR>> '1130337016',
'DestinationNumber' => '551199117099', 'Balance' => '-47.796',<BR>>
'startTime' => '2009-11-27 12:07:35', 'Cost' => '0.89',<BR>>
'transactionDescription' => 'Termination', 'billing' =>
'Limited',<BR>> 'RealTime' => '0:20' }, { 'Time' => '1:00', 'Limit'
=> '5', 'DNIS' =><BR>> '56012', 'destinationDescription' =>
'Brasil - Roc', 'Income' => '0.0000',<BR>> 'controlNumber' =>
'2414568', 'ANI' => '1130337016', 'DestinationNumber' =><BR>>
'551130337005', 'Balance' => '-48.086', 'startTime' =>
'2009-11-27<BR>> 12:06:08', 'Cost' => '0.29', 'transactionDescription'
=> 'Termination',<BR>> 'billing' => 'Limited', 'RealTime' =>
'0:21' }, { 'Time' => '0:00', 'Limit'<BR>> => '5', 'DNIS' => {},
'destinationDescription' => {}, 'Income' => '50',<BR>>
'controlNumber' => '2414568', 'ANI' => {}, 'DestinationNumber' =>
{},<BR>> 'Balance' => '1.914', 'startTime' => '2009-11-26
18:05:36', 'Cost' =><BR>> '0.0000', 'transactionDescription' =>
'Payment', 'billing' => 'Limited',<BR>> 'RealTime' => '0:00' }, {
'Time' => '1:00', 'Limit' => '5', 'DNIS' =><BR>> '30338031',
'destinationDescription' => 'Brasil - Roc', 'Income' =><BR>>
'0.0000', 'controlNumber' => '2414568', 'ANI' => '1145822125',<BR>>
'DestinationNumber' => '551145215888', 'Balance' => '1.624',
'startTime' =><BR>> '2009-11-25 18:11:25', 'Cost' => '0.29',
'transactionDescription' =><BR>> 'Termination', 'billing' =>
'Limited', 'RealTime' => '0:47' }, { 'Time' =><BR>> '1:00', 'Limit'
=> '5', 'DNIS' => '56012', 'destinationDescription' =><BR>>
'Brasil - Roc', 'Income' => '0.0000', 'controlNumber' => '2414568',
'ANI' =><BR>> '1145822125', 'DestinationNumber' => '551155478001',
'Balance' => '1.334',<BR>> 'startTime' => '2009-11-25 11:55:47',
'Cost' => '0.29',<BR>> 'transactionDescription' => 'Termination',
'billing' => 'Limited',<BR>> 'RealTime' => '0:09' }, { 'Time' =>
'1:00', 'Limit' => '5', 'DNIS' =><BR>> '56012',
'destinationDescription' => 'Brasil - Roc', 'Income' =>
'0.0000',<BR>> 'controlNumber' => '2414568', 'ANI' => '1145822125',
'DestinationNumber' =><BR>> '551140040435', 'Balance' => '1.044',
'startTime' => '2009-11-25 11:48:00',<BR>> 'Cost' => '0.29',
'transactionDescription' => 'Termination', 'billing' =><BR>>
'Limited', 'RealTime' => '0:07' }, { 'Time' => '1:36', 'Limit' =>
'5',<BR>> 'DNIS' => '56012', 'destinationDescription' => 'Brasil -
Roc', 'Income' =><BR>> '0.0000', 'controlNumber' => '2414568',
'ANI' => '1145822125',<BR>> 'DestinationNumber' => '551140040435',
'Balance' => '0.58', 'startTime' =><BR>> '2009-11-25 11:09:02',
'Cost' => '0.464', 'transactionDescription' =><BR>> 'Termination',
'billing' => 'Limited', 'RealTime' => '1:31' }, { 'Time' =><BR>>
'1:00', 'Limit' => '5', 'DNIS' => '56012', 'destinationDescription'
=><BR>> 'Brasil - Roc', 'Income' => '0.0000', 'controlNumber' =>
'2414568', 'ANI' =><BR>> '1145822125', 'DestinationNumber' =>
'551138330767', 'Balance' => '0.29',<BR>> 'startTime' =>
'2009-11-25 10:11:35', 'Cost' => '0.29',<BR>> 'transactionDescription'
=> 'Termination', 'billing' => 'Limited',<BR>> 'RealTime' =>
'0:47' }, { 'Time' => '1:00', 'Limit' => '5', 'DNIS' =><BR>>
'56012', 'destinationDescription' => 'Brasil - Roc', 'Income' =>
'0.0000',<BR>> 'controlNumber' => '2414568', 'ANI' => '1145822125',
'DestinationNumber' =><BR>> '551138330767', 'Balance' => '0.0000',
'startTime' => '2009-11-25 09:50:25',<BR>> 'Cost' => '0.29',
'transactionDescription' => 'Termination', 'billing' =><BR>>
'Limited', 'RealTime' => '0:52' } ], 'Val' => { 'UserID' =>
'2414568' },<BR>> 'STATUS' => '0' } } } }, 'xmlns:xsd' => '<A
href="http://www.w3.org/2001/XMLSchema"
target=_blank>http://www.w3.org/2001/XMLSchema</A>',<BR>> 'xmlns:soap'
=> '<A href="http://schemas.xmlsoap.org/soap/envelope/"
target=_blank>http://schemas.xmlsoap.org/soap/envelope/</A>' };<BR>>
=====================================================================<BR>><BR>>
use LWP::UserAgent;<BR>> use HTTP::Request;<BR>> use
XML::Simple;<BR>> use Data::Dumper;<BR>><BR>> my $message =
'<?xml version="1.0" encoding="utf-8"?><BR>> <soap:Envelope
xmlns:xsi="<A href="http://www.w3.org/2001/XMLSchema-instance"
target=_blank>http://www.w3.org/2001/XMLSchema-instance</A>"<BR>>
xmlns:xsd="<A href="http://www.w3.org/2001/XMLSchema"
target=_blank>http://www.w3.org/2001/XMLSchema</A>"<BR>> xmlns:soap="<A
href="http://schemas.xmlsoap.org/soap/envelope/"
target=_blank>http://schemas.xmlsoap.org/soap/envelope/</A>"><BR>>
<soap:Header><BR>> <AuthHeader
xmlns="vscws"><BR>>
<distriID>XXXX</distriID><BR>>
<password>XXXXXX</password><BR>>
</AuthHeader><BR>> </soap:Header><BR>>
<soap:Body><BR>> <getUserTransactions
xmlns="vscws"><BR>>
<controlNumber>XXXXXX</controlNumber><BR>>
<transactionType></transactionType><BR>>
<dateFrom>2009-11-10</dateFrom><BR>>
<dateTo>2009-11-30</dateTo><BR>>
</getUserTransactions><BR>> </soap:Body><BR>>
</soap:Envelope>';<BR>><BR>> my $length =
length($message);<BR>><BR>> my $userAgent =
LWP::UserAgent->new();<BR>> my $request = HTTP::Request->new(POST
=><BR>> '<A href="http://200.XXX.XXX.XX:90/ws.asmx%27"
target=_blank>http://200.XXX.XXX.XX:90/ws.asmx'</A>);<BR>>
$request->header(SOAPAction => '"vscws/getUserTransactions"');<BR>>
$request->content_type("text/xml; charset=utf-8");<BR>>
$request->content_length($length);<BR>>
$request->content($message);<BR>><BR>> my $response =
$userAgent->request($request);<BR>><BR>> #<BR>> #
Parseando o resultado (XML) do servidor<BR>> #<BR>> my
$ref = XMLin( $response->content ) or die $!;<BR>> my $xml =
XMLout( my $hashref );<BR>><BR>> for ( my $i = $#{
$ref->{getUserTransactions} }; $i > 0; $i-- ) {<BR>><BR>>
$startdate = "${
$ref->{getUserTransactions} }[$i]->{startTime}";<BR>>
$origem = "${
$ref->{getUserTransactions} }[$i]->{ANI}";<BR>>
$destino = "${
$ref->{getUserTransactions}<BR>>
}[$i]->{DestinationNumber}";<BR>>
$descrip = "${
$ref->{getUserTransactions}<BR>>
}[$i]->{destinationDescription}";<BR>>
$duration = "${ $ref->{getUserTransactions}
}[$i]->{Time}";<BR>>
$cost = "${
$ref->{getUserTransactions} }[$i]->{Cost}";<BR>><BR>>
$tabelaprint .= "<BR>>
<tr><BR>> <td><p
align=\"center\"><font face=\"Arial\"<BR>>
size=\"1\"><b>$startdate</b></font></td><BR>>
<td><p align=\"center\"><font
face=\"Arial\"<BR>> size=\"1\">$origem</font></td><BR>>
<td><p align=\"center\"><font
face=\"Arial\"<BR>>
size=\"1\"><b>$destino</b></font></td><BR>>
<td><p align=\"center\"><font
face=\"Arial\"<BR>>
size=\"1\"><b>$descrip</b></font></td><BR>>
<td><p align=\"center\"><font
face=\"Arial\"<BR>>
size=\"1\">$duration</font></td><BR>>
<td><p align=\"center\"><font
face=\"Arial\"<BR>> size=\"1\">$cost</font></td><BR>>
</tr><BR>> ";<BR>>
}<BR>><BR>> if($response->code == 200) {<BR>>
print "$tabelaprint";<BR>> }<BR>> else {<BR>>
print $response->error_as_HTML;<BR>> };<BR></DIV></DIV>Outra
coisa, você está fazendo o parser do content, e depois que você<BR>termina
você verifica se ele está ok ?<BR><BR>É ao contrário!<BR><BR>die unless
$response->code == 200<BR>#Agora você faz o parser aqui!!!<BR><BR>Você
precisa de um carro para chegar em uma cidade, depois disso você<BR>vai
queima-lo, o que seria certo:<BR>1 - Checar o motor antes de partir ?<BR>2 -
Checar o motor depois que você chegou e não precisa mais do carro ?<BR>
<DIV class=im><BR><BR><BR><BR><BR><BR><BR><BR>> Obrigado.<BR>> Marcio
Mello.<BR>> <A
href="mailto:marcio@modapoint.com.br">marcio@modapoint.com.br</A><BR></DIV>
<DIV>
<DIV></DIV>
<DIV class=h5>> _______________________________________________<BR>>
SaoPaulo-pm mailing list<BR>> <A
href="mailto:SaoPaulo-pm@pm.org">SaoPaulo-pm@pm.org</A><BR>> <A
href="http://mail.pm.org/mailman/listinfo/saopaulo-pm"
target=_blank>http://mail.pm.org/mailman/listinfo/saopaulo-pm</A><BR>><BR><BR><BR><BR>--<BR>Existe
dois tipos de pessoas, as que reclamam a vida inteira do que<BR>fazem, e as
que fazem o que nasceram para
fazer.<BR>_______________________________________________<BR>SaoPaulo-pm
mailing list<BR><A
href="mailto:SaoPaulo-pm@pm.org">SaoPaulo-pm@pm.org</A><BR><A
href="http://mail.pm.org/mailman/listinfo/saopaulo-pm"
target=_blank>http://mail.pm.org/mailman/listinfo/saopaulo-pm</A><BR></DIV></DIV></BLOCKQUOTE></DIV><BR><BR
clear=all><BR>-- <BR>André Garcia Carneiro<BR>Analista/Desenvolvedor
Perl<BR><BR><BR>
<P>
<HR>
<P></P>_______________________________________________<BR>SaoPaulo-pm mailing
list<BR>SaoPaulo-pm@pm.org<BR>http://mail.pm.org/mailman/listinfo/saopaulo-pm</BLOCKQUOTE></BODY></HTML>