Allora oggi ho iniziato un po a smanettare con un file xml e volevo interfacciarlo con un file php
Il mio file e' questo:
<?xml version="1.0" encoding="iso-8859-1"?>
<menu>
<voce livello="00" titolo="home"></voce>
<voce livello="01" titolo="chi siamo"></voce>
<voce livello="02" titolo="dove siamo"></voce>
<voce livello="02" titolo="servizi"></voce>
<voce livello="02" titolo="contatti"></voce>
</menu>
Io vorrei capire ma devo fare tutto questo per stampare l'attributo titolo?
Ho progettato male il file xml?
Codice PHP:
<?
$struct = array();
$xml_parser = xml_parser_create();
function startElement($parser, $name, $attrs)
{
global $struct;
$tag = array("name"=>$name,"attrs"=>$attrs);
array_push($struct,$tag);
}
function data($parser, $data)
{
global $struct,$i;
if(trim($data))
{
$struct[count($struct)-1]['data']=$data;
}
}
function endElement($parser, $name)
{
global $struct;
$struct[count($struct)-2]['child'][] = $struct[count($struct)-1];
array_pop($struct);
}
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "data");
$file = "primo.xml";
$parse = xml_parse($xml_parser,file_get_contents($file));
if(!$parse) {
die("XML parsing error");
}
xml_parser_free($xml_parser);
echo "<pre>";
print_r($struct);
echo "</pre>";
($struct["0"]["child"]);
echo $limite = count($struct["0"]["child"]) ;
echo $struct[0]["child"]["0"]["attrs"]["TITOLO"];
?>