Get values XML feed by name - PHP -


i'm using xml insert products db php. can access / read xml feed following code:

$xml=simplexml_load_file('testfeed.xml') or die("error: cannot create object"); foreach($xml->children() $product) {     $pname = $product->name;     $pdescr = $product->description;     echo $pname;     echo $pdescr;     } 

below example xml:

<product id="9"> <name>product x</name> <properties> <property name="categorypath"> <value>path-to-category</value> </property> <property name="stock"> <value>1</value> </property> </properties> </product> 

it's easy values name, how value of categorypath, since 1 inside properties->property->value , declared in <property name="categorypath">?

thanks!

the easiest way without looping through structures using xpath:

$values = $xml->xpath('//property[@name="categorypath"]/value'); 

just loop through returned array , cast each result string when needed, , you're done.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -