tibberous Posted May 25, 2010 Share Posted May 25, 2010 Lets say this is my xml: $xml = "<root><people><person><name>bob</name></person><person><name>trent</name></person></people></root>"; I want to be able to get $root->people as an array, then loop through $root->people[$i] and print out their names. Actionscript makes this remarkably easy with E4X, does PHP have something similar? I hate the xml_parser_create way of doing things - but using preg_match_all just feels like a hack. Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 25, 2010 Share Posted May 25, 2010 http://www.php.net/manual/en/function.simplexml-load-string.php http://www.php.net/manual/en/function.simplexml-load-file.php Quote Link to comment Share on other sites More sharing options...
tibberous Posted May 26, 2010 Author Share Posted May 26, 2010 Yeah - that's what I'm looking for, even though it either doesn't support full XML or is buggy. It won't read my XML if I leave the SOAP namespaced elements around it, even though FF and IE read the xml file as valid. I was able to get it to work by preg_matching one of the more-inner tags =/ Quote Link to comment Share on other sites More sharing options...
salathe Posted May 26, 2010 Share Posted May 26, 2010 it either doesn't support full XML or is buggy No, it seems you just haven't fully read the documentation. To access namespaced items, use the children method on an element. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.