Avendo un file xml chiamato link.xml così composto:
codice:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<database>
<categorie>
<cat>News</cat>
<scat>Locali</scat>
</categorie>
<categorie>
<cat>Sport</cat>
<scat>Calcio</scat>
</categorie>
</datsbase>
io lo leggo con questo php:
Codice PHP:
<?php
$indice = 256;
$contatore = 0;
$apri_xml = fopen("link.xml", 'r');
while(!feof($apri_xml))
{
$buffer = ltrim(Chop(fgets($apri_xml, $indice)));
if ($buffer == "<categorie>")
{
$cat = ltrim(Chop(fgets($apri_xml, $indice)));
$scat = ltrim(Chop(fgets($apri_xml, $indice)));
$cat = ereg_replace("<cat>", "", $cat);
$cat = ereg_replace("</cat>", "", $cat);
$scat = ereg_replace("<scat>", "", $scat);
$scat = ereg_replace("</scat>", "", $scat);
echo "Categorie: ".$cat."
Sottocategorie: ".$scat."
";
$contatore++;
}
}
fclose($apri_xml);
?>
Siccome però l'ho formattato in modo diverso da come lo vedi scritto, può anche darsi che dia qualche errore, ma penso che l'originale sia questo e dovrebbe funzionare correttamente.