Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/08/2011, 02:24
auri501
 
Fecha de Ingreso: octubre-2007
Mensajes: 130
Antigüedad: 16 años, 7 meses
Puntos: 2
leer xml con php

Buenos días a todos!
Estoy intentando leer un xml con esta estructura:
Cita:
<hashtable>
<entry><string>city</string>
<string>Madrid</string></entry>
<entry><string>langpref</string>
<string>en</string></entry>
</hashtable>
El código php que estoy usando es este:
Cita:
<?php
$cdCatalogXMLReader = new CDCatalogXMLReader();
$cdCatalogXMLReader->showCatalogAsTable('details-by-id.xml');

class CDCatalogXMLReader {
public function showCatalogAsTable($xmlPath) {
// Loads XML.
$doc = new DOMDocument();
$doc->load($xmlPath);
echo $doc->saveXML();
// Reading tag's value.


echo "<h1>Datos cliente</h1>";

// Reading all elements with tag name="cd".
$cds = $doc->getElementsByTagName( "entry" );

echo '<table border="1">';
echo '<tr><th>ID</th><th>Title</th><th>Artist</th><th>Country</th><th>Company</th><th>Price</th><th>Year</th></tr>';

foreach ($cds as $cd) {
echo '<tr>'; // Reading attributes.
echo '<td>' . $cd->getAttribute('entry') . '</td>';
echo '<td>' . $cd->getElementsByTagName("string")->item(0)->getAttribute('value') . '</td>';
echo '<td>' . $cd->getElementsByTagName("string")->item(0)->getAttribute('value') . '</td>';
echo '<td>' . $cd->getElementsByTagName("string")->item(0)->getAttribute('value') . '</td>';
echo '<td>' . $cd->getElementsByTagName("string")->item(0)->getAttribute('value') . '</td>';
echo '<td>' . $cd->getElementsByTagName("string")->item(0)->getAttribute('value') . '</td>';
echo '<td>' . $cd->getElementsByTagName("string")->item(0)->getAttribute('value') . '</td>';
echo '</tr>';
}
echo '</table>';
}
}
?>
Llega a crear las celdas pero vacías, no carga ningún valor. Alguien saben como leer esta estructura de xml? Gracias!!