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
Post a Comment