php - How to get individual xml subnodes when using $xpathvar->query? -


i try value of name, previewurl, description, etc when country name (e.g. <country name="us"> ) matches country of user xml results 1 below:

<offers>    <offer id="656">      <name>the hobbit android</name>      <platform>android smartphone & tablet</platform>      <dailycap>63</dailycap>      <previewurl>https://play.google.com/store/apps/details?id=com.kabam.fortress</previewurl>      <trackingurl>http://ads.ad4game.com/www/delivery/dck.php?offerid=656&zoneid=7711</trackingurl>      <description>the battle middle-earth has begun! play free , join thousands worldwide drive ..</description>      <restrictedtraffic> social traffic (facebook, etc), social traffic (facebook, etc) email marketingm, brand bidding</restrictedtraffic>      <countries>        <country name="us">          <optin>soi</optin><rate>$3.75</rate>          <enddate>2013-09-15 16:47:12</enddate>        </country>      </countries>    </offer>  </offers> 

when try php code below nodes concatenated 1 single string. how can name, previewurl, description, etc. individual strings when country name matches?

$xmldoc = new domdocument();         $xmldoc->load('http://traffic.ad4game.com/www/admin/offers-api.php');          $xpathvar = new domxpath($xmldoc);            $queryresult = $xpathvar->query('//country[@name="us"]/../..');          foreach($queryresult $result){                 echo $result->nodevalue;         } 

edit: expected output, expect after obtaining individual strings, expect like:

<div id="offer656"> <a href="http://ads.ad4game.com/www/delivery/dck.php?offerid=656&zoneid=7711"> hobbit android</a><br />the battle middle-earth has begun! play free , join thousands worldwide drive ..  </div> 

first, need iterate through child elements of xpath query, add /* @ end.

second, pass nodevalue results array can subscript individual strings (i.e., $value[0], $value[1], ...) or run foreach loop on array:

$xmldoc = new domdocument(); $xmldoc->load('http://traffic.ad4game.com/www/admin/offers-api.php');  $xpathvar = new domxpath($xmldoc);  // iterate through child elements  $queryresult = $xpathvar->query('//country[@name="us"]/../../*');  $value = []; foreach($queryresult $result){         // prints node values of xpath @ once         echo $result->nodevalue;          // passes each node value of xpath $value array         $value[] = $result->nodevalue;             }  // output $value array contents var_dump($value); 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -