Quote:
Originally Posted by ronverdonk
The code you posted does NOT work on the file you want to use. It was a very simple sample for just non-nested XML. You did not read the entry in that same forum thread that warned:And I agree with Andy, there are plenty XML parsers around, if you have PHP5 you can use SimpleXML, see SimpleXML
As for reading the file, you can do something like [php]$xmlstring = file_get_contents("filename");[/php] that reads the entire file into the variable $xmlstring.
Ronald :cool:
Thank you. That is indeed the way to read the content :)
I did what you said... I now used SAX parter and came to this:
$xfile = "http://www.izishop.net/export.php";
$xparser=xml_parser_create();
xml_set_element_handler($xparser, "startingHandler", "endingHandler");
xml_set_character_data_handler($xparser, "cdataHandler");
if(!($fp=fopen($xfile,"r")))
{
die ("File does not exist");
}
while($data=fread($fp, 4096))
{
if(!xml_parse($xparser,$data,feof($fp)))
{
die("XML parse error: xml_error_string(xml_get_error_code($xparser))");
}
}
xml_parser_free($xml_parser);
function startingHandler($xparser, $element_name, $attributes)
{
echo "Opening Tag:<b>$element_name</b><br>";
while (list($key,$value)=each($attributes))
{
echo "Attribute:<b><i>$key=$value</i></b><br>";
}
}
function endingHandler($xparser, $element_name)
{
echo "Closing Tag:<b>$element_name</b><br>";
}
function cdataHandler($xparser, $cdata)
{
echo "CDATA: <i><u>$cdata</u></i><br>";
}
?>
This replays this:
http://krebs.si/xml/test2.php
So what I want to do now is to insert some of those atributes ( id, link, name, brand... ) into mysql database.
Thank you.