impulse() wrote:I tried using simplexml_load_file but was told that it didn't have enough functionality
nonsense, the example proves it can do what you're asking for. And see how easy it was done. If simplexml doesn't provide needed functionality you can always use
dom_import_simplexml to switch the interface (the internal representation is the same).
One "disadvantage" of a dom parser is the whole document is represented by the model. If the document is large and you only need a small portion of the document this may be a waste of memory and cpu time. If this is an issue you use a sax parser that provides you the data as it is read - on-the-fly. This way the whole document can be parsed but only the portions needed are held in memory.
There are hybrid implementations attepting to combine the best of dom and sax. But I haven't seen one for php yet.
Is the xml data size an issue?
If you must implement it using xml_set_..._handler you need to store the current status for each start/end of an element.
If you enter a new <friend> element you create a new container for the data of this friend element (as simple example an array)
start_tag, end_tag and tag_contents must share access to the flags and the curent container.
If you are within a <friend> element and enter a <name> element you store subsequent character data in the current <friend> container until this <name> element ends. Same with age, height and sex.
When the <friend> elements ends you check the current data container and do whatever you want to do with a <friend> element (in your case write the data to mysql).
Now you can discard the current container and wait for a new <friend> element.