Then why is there never anything even remotly connected to the tagname in your code or in your questions?
Code: Select all
<?php
function start_tag($parser, $name, $attribs) {
$name = strtolower($name);
if ( 'mytag'===$name ) {
echo "start: mytag<br />\n";
}
else {
echo " ignoring tag<br />\n";
}
}
function end_tag($parser, $name) {
$name = strtolower($name);
if ( 'mytag'===$name ) {
echo "end: mytag<br />\n";
}
}
function tag_contents($parser, $data) {
}
$parser = xml_parser_create();
xml_set_element_handler($parser, 'start_tag', 'end_tag');
xml_set_character_data_handler($parser, 'tag_contents');
$data = '<root>
<mytag>abc</mytag>
<mytag>def</mytag>
<something>abc</something>
<else>def</else>
<mytag>abc</mytag>
</root>';
xml_parse($parser, $data, true);
?>
Even if I do evaluate the start/end tag names, I can still see myself using an array with a counter to store the contents between the start/end tags.
Maybe, but there's no need for it at all

Q: For which elements/tags must your script care? Under which conditions?
A: Only for name,age,height,sex. And only while beeing "within" a friend element.
Q: For the given (simple) xml document structure what information must be shared therefore between the three functions?
A: "Am I within a friend element?", "What's the current element?" -> "What's the current element's contents (so far)?"
Q: At which point must all data for
one recordset have been provided?
A: When the parser reaches the end tag of a friend element (</friend>) no data can be added to this element anymore. Either all data has been gathered or the record can't be fixed.
Q: Where do you process the data of one friend element? / When can you insert a mysql recordset?
A: In my end_tag handler each time the end of a friend element is signaled. I check the current data shared between the function, build the mysql query and then re-initialize the shared data.