Leitura de XML/Array
Boa noite, pessoal!
Estou tentando encontrar a melhor solução para organizar os dados que estou obtendo através de um XML. A estrutura do XML está vindo de uma tabela dessa forma:
/applications/core/interface/imageproxy/imageproxy.php?img=http://i.imgur.com/xYp201F.png?1&key=9c476bbd04beac1ee80dba87de3cfdf71e4786602d547345abf4ace751f1a20d" alt="xYp201F.png?1" />
Estou utilizando o Yahoo! YQL e ele me retorna o seguinte XML com o código abaixo:
$table = getYqlResult(" select * from html where url = '$url' and xpath='//tr' ", 'xml'); function getYqlResult($query){ $yql_base_url = "http://query.yahooapis.com/v1/public/yql"; $yql_query_url = $yql_base_url . "?q=" . urlencode($query); return simplexml_load_file($yql_query_url);} foreach ($table->results->tr as $node) { echo '<pre>'; echo($node->td[0]->p); echo($node->td[1]->p); echo '</pre>'; }
<?xml version="1.0" encoding="UTF-8"?><query xmlns:yahoo="http://www.yahooapis.com/v1/base.rng" yahoo:count="20" yahoo:created="2013-12-01T21:22:57Z" yahoo:lang="en-US"> <results> <tr class="dr-table-subheader rich-table-subheader Grid-Titulo"> <th class="dr-table-subheadercell rich-table-subheadercell Grid-Titulo" id="j_id_jsp_52511974_1:tbGridIda:j_id_jsp_52511974_7header" scope="col"> <div id="j_id_jsp_52511974_1:tbGridIda:j_id_jsp_52511974_7header:sortDiv"> <p>Sequência</p> </div> </th> <th class="dr-table-subheadercell rich-table-subheadercell Grid-Titulo" id="j_id_jsp_52511974_1:tbGridIda:j_id_jsp_52511974_10header" scope="col"> <div id="j_id_jsp_52511974_1:tbGridIda:j_id_jsp_52511974_10header:sortDiv"> <p>Via</p> </div> </th> </tr> <tr class="dr-table-firstrow rich-table-firstrow"> <td class="dr-table-cell rich-table-cell Grid-Registro" id="j_id_jsp_52511974_1:tbGridIda:0:j_id_jsp_52511974_7"> <p>001</p> </td> <td class="dr-table-cell rich-table-cell Grid-Registro" id="j_id_jsp_52511974_1:tbGridIda:0:j_id_jsp_52511974_10"> <p>TERMINAL CONJ. GRACILIANO RAMOS</p> </td> </tr> <tr class="dr-table-firstrow rich-table-firstrow"> <td class="dr-table-cell rich-table-cell Grid-Registro" id="j_id_jsp_52511974_1:tbGridIda:1:j_id_jsp_52511974_7"> <p>002</p> </td> <td class="dr-table-cell rich-table-cell Grid-Registro" id="j_id_jsp_52511974_1:tbGridIda:1:j_id_jsp_52511974_10"> <p>AV. EMP. NELSON OLIVEIRA MENEZES</p> </td> </tr> <tr class="dr-table-firstrow rich-table-firstrow"> <td class="dr-table-cell rich-table-cell Grid-Registro" id="j_id_jsp_52511974_1:tbGridIda:2:j_id_jsp_52511974_7"> <p>003</p> </td> <td class="dr-table-cell rich-table-cell Grid-Registro" id="j_id_jsp_52511974_1:tbGridIda:2:j_id_jsp_52511974_10"> <p>AV. DA PAZ</p> </td> </tr> <tr class="dr-table-firstrow rich-table-firstrow"> <td class="dr-table-cell rich-table-cell Grid-Registro" id="j_id_jsp_52511974_1:tbGridIda:3:j_id_jsp_52511974_7"> <p>004</p> </td> <td class="dr-table-cell rich-table-cell Grid-Registro" id="j_id_jsp_52511974_1:tbGridIda:3:j_id_jsp_52511974_10"> <p>ITINERARIO VOLTA - B. GONZAGA</p> </td> </tr> <tr class="dr-table-firstrow rich-table-firstrow"> <td class="dr-table-cell rich-table-cell Grid-Registro" id="j_id_jsp_52511974_1:tbGridIda:4:j_id_jsp_52511974_7"> <p>005</p> </td> <td class="dr-table-cell rich-table-cell Grid-Registro" id="j_id_jsp_52511974_1:tbGridIda:4:j_id_jsp_52511974_10"> <p>AV. TANCREDO NEVES</p> </td> </tr> <tr class="dr-table-firstrow rich-table-firstrow"> <td class="dr-table-cell rich-table-cell Grid-Registro" id="j_id_jsp_52511974_1:tbGridIda:5:j_id_jsp_52511974_7"> <p>006</p> </td> <td class="dr-table-cell rich-table-cell Grid-Registro" id="j_id_jsp_52511974_1:tbGridIda:5:j_id_jsp_52511974_10"> <p>RUA SAO PEDRO</p> </td> </tr> <tr class="dr-table-firstrow rich-table-firstrow"> <td class="dr-table-cell rich-table-cell Grid-Registro" id="j_id_jsp_52511974_1:tbGridIda:6:j_id_jsp_52511974_7"> <p>007</p> </td> <td class="dr-table-cell rich-table-cell Grid-Registro" id="j_id_jsp_52511974_1:tbGridIda:6:j_id_jsp_52511974_10"> <p>RUA GABINO BEZOURO</p> </td> </tr> <tr class="dr-table-firstrow rich-table-firstrow"> <td class="dr-table-cell rich-table-cell Grid-Registro" id="j_id_jsp_52511974_1:tbGridIda:7:j_id_jsp_52511974_7"> <p>008</p> </td> <td class="dr-table-cell rich-table-cell Grid-Registro" id="j_id_jsp_52511974_1:tbGridIda:7:j_id_jsp_52511974_10"> <p>RUA FLORENCIO DE ABREU</p> </td> </tr> <tr class="dr-table-subheader rich-table-subheader Grid-Titulo"> <th class="dr-table-subheadercell rich-table-subheadercell Grid-Titulo" id="j_id_jsp_52511974_1:tbGridVolta:j_id_jsp_52511974_16header" scope="col"> <div id="j_id_jsp_52511974_1:tbGridVolta:j_id_jsp_52511974_16header:sortDiv"> <p>Sequência</p> </div> </th> <th class="dr-table-subheadercell rich-table-subheadercell Grid-Titulo" id="j_id_jsp_52511974_1:tbGridVolta:j_id_jsp_52511974_19header" scope="col"> <div id="j_id_jsp_52511974_1:tbGridVolta:j_id_jsp_52511974_19header:sortDiv"> <p>Via</p> </div> </th> </tr> <tr class="dr-table-firstrow rich-table-firstrow"> <td class="dr-table-cell rich-table-cell Grid-Registro" id="j_id_jsp_52511974_1:tbGridVolta:0:j_id_jsp_52511974_16"> <p>001</p> </td> <td class="dr-table-cell rich-table-cell Grid-Registro" id="j_id_jsp_52511974_1:tbGridVolta:0:j_id_jsp_52511974_19"> <p>RUA FLORENCIO DE ABREU</p> </td> </tr> <tr class="dr-table-firstrow rich-table-firstrow"> <td class="dr-table-cell rich-table-cell Grid-Registro" id="j_id_jsp_52511974_1:tbGridVolta:1:j_id_jsp_52511974_16"> <p>002</p> </td> <td class="dr-table-cell rich-table-cell Grid-Registro" id="j_id_jsp_52511974_1:tbGridVolta:1:j_id_jsp_52511974_19"> <p>RUA 01 - VILLAGE I</p> </td> </tr><tr class="dr-table-firstrow rich-table-firstrow"> <td class="dr-table-cell rich-table-cell Grid-Registro" id="j_id_jsp_52511974_1:tbGridVolta:2:j_id_jsp_52511974_16"> <p>003</p> </td> <td class="dr-table-cell rich-table-cell Grid-Registro" id="j_id_jsp_52511974_1:tbGridVolta:2:j_id_jsp_52511974_19"> <p>RUA SAO PEDRO</p> </td> </tr> <tr class="dr-table-firstrow rich-table-firstrow"> <td class="dr-table-cell rich-table-cell Grid-Registro" id="j_id_jsp_52511974_1:tbGridVolta:3:j_id_jsp_52511974_16"> <p>004</p> </td> <td class="dr-table-cell rich-table-cell Grid-Registro" id="j_id_jsp_52511974_1:tbGridVolta:3:j_id_jsp_52511974_19"> <p>AV. TANCREDO NEVES</p> </td> </tr> <tr class="dr-table-firstrow rich-table-firstrow"> <td class="dr-table-cell rich-table-cell Grid-Registro" id="j_id_jsp_52511974_1:tbGridVolta:4:j_id_jsp_52511974_16"> <p>005</p> </td> <td class="dr-table-cell rich-table-cell Grid-Registro" id="j_id_jsp_52511974_1:tbGridVolta:4:j_id_jsp_52511974_19"> <p>RUA BENEDITO CALACA LOUREIRO</p> </td> </tr><tr class="dr-table-firstrow rich-table-firstrow"> <td class="dr-table-cell rich-table-cell Grid-Registro" id="j_id_jsp_52511974_1:tbGridVolta:5:j_id_jsp_52511974_16"> <p>006</p> </td> <td class="dr-table-cell rich-table-cell Grid-Registro" id="j_id_jsp_52511974_1:tbGridVolta:5:j_id_jsp_52511974_19"> <p>RUA PERIMETRAL 03</p> </td> </tr><tr class="dr-table-firstrow rich-table-firstrow"> <td class="dr-table-cell rich-table-cell Grid-Registro" id="j_id_jsp_52511974_1:tbGridVolta:6:j_id_jsp_52511974_16"> <p>007</p> </td> <td class="dr-table-cell rich-table-cell Grid-Registro" id="j_id_jsp_52511974_1:tbGridVolta:6:j_id_jsp_52511974_19"> <p>RUA JOSE MAILTON DOS SANTOS</p> </td> </tr> <tr class="dr-table-firstrow rich-table-firstrow"> <td class="dr-table-cell rich-table-cell Grid-Registro" id="j_id_jsp_52511974_1:tbGridVolta:7:j_id_jsp_52511974_16"> <p>008</p> </td> <td class="dr-table-cell rich-table-cell Grid-Registro" id="j_id_jsp_52511974_1:tbGridVolta:7:j_id_jsp_52511974_19"> <p>RUA 01</p> </td> </tr> <tr class="dr-table-firstrow rich-table-firstrow"> <td class="dr-table-cell rich-table-cell Grid-Registro" id="j_id_jsp_52511974_1:tbGridVolta:8:j_id_jsp_52511974_16"> <p>009</p> </td> <td class="dr-table-cell rich-table-cell Grid-Registro" id="j_id_jsp_52511974_1:tbGridVolta:8:j_id_jsp_52511974_19"> <p>TERMINAL CONJ. GRACILIANO RAMOS</p> </td> </tr> <tr class="dr-table-firstrow rich-table-firstrow"> <td class="dr-table-cell rich-table-cell Grid-Registro" id="j_id_jsp_52511974_1:tbGridVolta:9:j_id_jsp_52511974_16"> <p>010</p> </td> <td class="dr-table-cell rich-table-cell Grid-Registro" id="j_id_jsp_52511974_1:tbGridVolta:9:j_id_jsp_52511974_19"> <p>AV. EMP. NELSON OLIVEIRA MENEZES</p> </td> </tr> </results></query><!-- total: 1275 --><!-- engine1.yql.bf1.yahoo.com -->
Qual a melhor forma para que eu organize os dados e obtenha os valores que estão dentro do atributo <p> ? Pois terei de organizar esses dados e inseri-los num banco de dados.
Alguma alternativa a solução?
Discussão (4)
Carregando comentários...