douxing6434
douxing6434
2017-04-13 12:26

simplexml_load_string访问标记值

  • xml
  • php

I have problem with accessing value of XML tag. Here is and XML file part:

    <VAST version="3.0">
<Ad id="192347">
<InLine>
<AdSystem version="1.0">Appnext VAST</AdSystem>
<AdTitle>Empire: Four Kingdoms</AdTitle>
<Impression>
https://admin.appnext.com/pView.aspx?b=192347&z=25526&c=125501&tid=vast
</Impression>
<Description>
Become a mighty emperor of the four kingdoms in this award-winning MMO strategy game!
</Description>
<Pricing>"cpi","USD","1.407"</Pricing>
<Error>
https://admin.appnext.com/tp12.aspx?ads_type=VAST&tid=VAST&vid=1&pid=0fa643ba-a3e5-4f01-bf49-89354fbd0562&ref=error&bid=192347&cid=125501
</Error>
<Creatives>
<Creative id="192347">
<Linear>
<Duration>00:00:30.000</Duration>
<VideoClicks>...</VideoClicks>
<TrackingEvents>...</TrackingEvents>
<MediaFiles>
<MediaFile delivery="progressive" type="video/mp4" width="640" height="360" bitrate="500" scalable="true" maintainAspectRatio="true">
<![CDATA[
https://appnext-a.akamaihd.net/banner/video/video-192347-30_o.mp4?rnd=1488986809
]]>
</MediaFile>
<MediaFile delivery="progressive" type="video/mp4" width="320" height="180" bitrate="500" scalable="true" maintainAspectRatio="true">
<![CDATA[
https://appnext-a.akamaihd.net/banner/video/video-192347-30.mp4?rnd=1488986813
]]>
</MediaFile>
</MediaFiles>
</Linear>
</Creative>``

I need to access MediaFile tag value but i only get atributes values like: delivery, type etc. Here is code i already have made:

$xml = file_get_contents('https://admin.appnext.com/offerWallApi.aspx?id=0fa643ba-a3e5-4f01-bf49-89354fbd0562&type=vast&vast_ver=3.0&tid=vast&cv=1&duration=all&pbk=test&ip=8.8.8.8', false, $context);
    $response = simplexml_load_string($xml);
    $files = $response->Ad->InLine->Creatives->Creative->Linear->MediaFiles->MediaFile;
    foreach($files as $file) {
        var_dump($file);
    }

And PHP response:

object(SimpleXMLElement)#5 (1) { ["@attributes"]=> array(7) { ["delivery"]=> string(11) "progressive" ["type"]=> string(9) "video/mp4" ["width"]=> string(3) "640" ["height"]=> string(3) "360" ["bitrate"]=> string(3) "500" ["scalable"]=> string(4) "true" ["maintainAspectRatio"]=> string(4) "true" } } object(SimpleXMLElement)#4 (1) { ["@attributes"]=> array(7) { ["delivery"]=> string(11) "progressive" ["type"]=> string(9) "video/mp4" ["width"]=> string(3) "320" ["height"]=> string(3) "180" ["bitrate"]=> string(3) "500" ["scalable"]=> string(4) "true" ["maintainAspectRatio"]=> string(4) "true" } }

Thanks in advance for any help.

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答