php - Why is this xml parsing producing only one element? -


i having trouble parsing xml. want access array of item(s). have tried $xml->channel->item , $xml->channel["item"] neither works.

here php code have:

$xml=simplexml_load_file("my file.xml"); $channel = $xml->channel; $items = $channel->item; var_dump($channel); var_dump($items); //this showing 1 item, when there many 

here beginning of output var_dump($channel)

object(simplexmlelement)#4 (7) {   ["title"]=>   string(11) "title"   ["link"]=>   string(30) "mylink/"   ["description"]=>   string(128) "description"   ["pubdate"]=>   string(31) "fri, 27 jun 2014 04:24:24 -0700"   ["generator"]=>   string(57) "http://tumblr2wordpress/0.4(tumblr2wordpress.benapps.net)"   ["language"]=>   string(2) "en"   ["item"]=>   array(374) {     [0]=>     object(simplexmlelement)#69 (7) {       ["link"]=>       string(46) "link"       ["pubdate"]=>       string(31) "thu, 26 jun 2014 15:19:41 +0000"       ["category"]=>       array(2) {         [0]=>         object(simplexmlelement)#443 (0) {         }         [1]=>         object(simplexmlelement)#444 (1) {           ["@attributes"]=>           array(2) {             ["domain"]=>             string(8) "category"             ["nicename"]=>             string(7) "regular"           }         }       }       ["guid"]=>       string(46) "link"       ["comment"]=>       object(simplexmlelement)#445 (0) {       }       ["title"]=>       string(18) "ran 8 miles today!"       ["description"]=>       object(simplexmlelement)#446 (0) {       }     }     [1]=> more here 

if items grouping of items, keep in mind you're still dealing simplexml object. use foreach loop go on each item , extract properties.

foreach($channel->item $singleitem) {     //item properties accessible each } 

another option have use simplexml's xpath function return array of objects match xpath. can share example of if want well.


Comments

Popular posts from this blog

Unable to open serial port using Putty to bluetooth device on windows 7 64 bit -

bash - How do you programmatically add a bats test? -

java - Getting exception in JDBC thin driver -