having a few problems with an xml parser if anyones got a bit of time, much appreciated.
basically my script (php) connects to my database, and frm a table each row has an entry which related to an xml file. So one row might by id | xml_file_name
I want to cycle through these rows, parsing each file and echo'ing out the data.
Easy, only thing is my parser seems to get stuck after one, the data seems to get trapped in the parser so each time I just get the same stuff echo'ed out.
not sure if theres any easy way to clean the parser out or something after each cycle? bits and bobs of code below, help is much appreciated
Im using a while loop to go through all the records, inside the loop I have...
PHP Code:
$parser = xml_parser_create("UTF-8");
xml_set_element_handler($parser, "xmlStartTag", "xmlEndTag");
xml_set_character_data_handler($parser, "xmlCDATA");
xml_parse($parser,$xml,true);
foreach($records as $data) {
echo $data["NAME"];
}
xml_parser_free($parser);
outside the loop i've got the rest of the parser...
PHP Code:
function xmlStartTag($parser, $name, $attribs)
{
global $currentRecord;
global $currentTag;
global $inRecord;
if ($name == "TAGNAME")
{
$inRecord = true;
$currentRecord = array();
}
if ($inRecord)
{
$currentTag = $name;
}
}
function xmlCDATA($parser, $cdata)
{
global $currentRecord;
global $currentTag;
$currentRecord[$currentTag] .= $cdata;
}
function xmlEndTag($parser, $name)
{
global $records;
global $currentRecord;
global $inRecord;
if ($name == "TAGNAME")
{
$inRecord = false;
$records[] = $currentRecord;
}
}