PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I know I've been advied on here many time to use return for transporting variables but I'm confortable with globals at the moment which is why I've used them in the below code.
The code is to try and pass all data parsed from an XML file into an array.
You don't need to store all the contents of all tags. If you do there's no advantage over using dom (e.g. simplexml) but all the disadvantage of writing parser code yourself.
You only need to store the element content of <name>,<age>, <height> and <sex> when you're "within" a <friend> element.
Initialize some sort of container for the data you need to store for the current <friend> element. You will be notified via start_tag() when you "enter" a <friend> element (and also when you enter <name>,<age>, <height> and <sex>).
When you leave the <friend> element you can process the previously stored data and then discard the current container(i.e. the data of the <firend> element you just processed). You will be notifie via end_tag() when you "leave" an element.
I've been told that if I can learn how to insert XML data into a MySQL DB I can move into the programming department at the company where I work now for training. I work in technical support at the moment so you can understand my eagerness to complete this . So that's why I've spent nearly every minute of the weekend trying everything I can to get this working.
So far the best results I've had is inserting every tags data onto a single line in a MySQL DB. I just can't get my head around seperating the values into the groups of <Friend> (1, 2, 3 or 4) and then <Name>, <Age> & <Sex>. I'd preferably like a layout like
Again: You would use a DOM interface like simplexml if you wanted this. But you don't want it (or rather: have been told not to use it - you said so in another of numerous existing threads on the same topic)
You want:
<friend> -> $container = array();
$container['name'] = content of <name>
$container['age'] = content of <age>
$container['height'] = content of <height>
$container['sex'] = content of <sex>
</friend> -> process $container, then discard $container.