Create PHP variables with data contained in a XML node

WEBTOR

New Member
I'm having some serious trouble with this. What I'm trying to do is 'extract' all the contents of a specific node in XML, and turn these into PHP variables, in order to use them later on.Heres a small sample XML test data set I'm using.\[code\]<RECIPES><RECIPE><TI>Cinnamon Rolls</TI><IN>1/2 ea Sweet dough mixture</IN><IN>1/2 c Packed light brown sugar</IN><IN>1/2 c Pecans; chopped</IN><IN>1/2 c Dark seedless raisins</IN><IN>1 tsp Ground cinnamon</IN><IN>1/4 c Butter OR margarine; melted</IN><IN>Sugar Glaze (below opt)</IN><PR>Some Stuff.</PR></RECIPE><RECIPE><TI>SWEET BISCUITS</TI><IN>2 c Baking mix</IN><IN>2/3 c Milk</IN><IN>1/4 c Cinnamon Sugar</IN><IN>2 tb Butter</IN><PR>Some other stuff</PR></RECIPE><RECIPE>\[/code\](Theres actually about 900's of these)What I want to achieve is to extract the data from each node, and convert them to a variable; Below is what I hope to end up with.\[code\]$variable="Cinamon Rolls";$variable2="Sweet Biscuits";\[/code\]Is there a way to accomplish this? From what I've been researching i'm pretty sure it's something to do with SimpleXML. I've managed to output the contents individually, but just can't figure out how to then store them.Problem is solvedThanks everyone for the help,\[code\] $obj = simplexml_load_string($xml); foreach($obj->RECIPE as $r) { $variable = (string)$r->TI; echo $variable; }\[/code\]Superb, thanks very much. Saved my ass.
 
Back
Top