简单的xml无法获取所有属性

时间:2019-06-08 17:48:59

标签: php simplexml simplexml-load-string

我正在使用此file_get_contents来获取xml数据,并使用simplexml_load_string方法来解析xml。

$content                         =  file_get_contents($url);

if ($content !== FALSE) {

    $xml                         =  simplexml_load_string($content);

    if ($xml instanceof \SimpleXMLElement) {

            $data                    =  json_decode(json_encode($xml), true);
            $items                   =  $data["channel"]["item"] ?? [];
    }
}

dd($items);

问题是,如果我在浏览器上请求url,我会得到

<item><title>Meghan Markle and Kate Middleton make telling move at Trooping the Colour: ''Nothing makes me more happy''</title><link>http://links.precise-media.co.uk/e.aspx?articleid=478184003&clientid=29638&agreementid=151313</link><description>that they've been actively trying to dispel during public appearances, like in March when they shared a kiss on the cheek when greeting one another during a church service on Commonwealth Day.Prince Charles and Prince William weren't in the horse-drawn carriage on Saturday because, as heirs the thrown high in the line of succession, they ride in separately on horses.Unattributed[sourcelink]https://uk.news.yahoo.com/meghan-markle-kate-middleton-telling-111000742.html[/sourcelink]</description><author>Unattributed</author><category>UK</category><guid>478184003</guid><pubDate>08/06/2019</pubDate><precise:isscannable>1</precise:isscannable><precise:daysviewableremaining>27</precise:daysviewableremaining><precise:pagenum>0</precise:pagenum><precise:numberofpages>1</precise:numberofpages><precise:tiffile/><precise:mediaid>1106</precise:mediaid><precise:medianame>Internet</precise:medianame><precise:parentheadline/><precise:editionnumber>1</precise:editionnumber><precise:sectionname>Main</precise:sectionname><precise:searchword>Commonwealth Day - UK</precise:searchword><createddate>08/06/2019</createddate><precise:authordID>-78458707</precise:authordID><precise:searchwordID>1228830</precise:searchwordID><precise:avevalue>0.0000</precise:avevalue><precise:area>0</precise:area><precise:dateprocessed>08/06/2019</precise:dateprocessed><precise:client><precise:clientid>29638</precise:clientid><precise:clientname>Commonwealth Secretariat</precise:clientname><precise:agreement><precise:agreementid>151313</precise:agreementid><precise:agreementname>Commonwealth Secretariat Media Coverage</precise:agreementname><precise:category><precise:catid>406235</precise:catid><precise:categoryname>UK</precise:categoryname><precise:publication><precise:pubid>125887</precise:pubid><precise:pubname>Yahoo! UK and Ireland (Web)</precise:pubname><precise:pubcode/><precise:pubtype>Internet</precise:pubtype><precise:puborder>1</precise:puborder><precise:isscannable>1</precise:isscannable><precise:iscla>0</precise:iscla><precise:isnla>0</precise:isnla><precise:isclascannable>1</precise:isclascannable><precise:country/><precise:website/><precise:circulation>1030766</precise:circulation><precise:averate>0.0000</precise:averate></precise:publication></precise:category></precise:agreement></precise:client></item>

但是我得到的结果是这个

0 => array:8 [▼
"title" => "Meghan Markle and Kate Middleton make telling move at Trooping the Colour: ''Nothing makes me more happy''"
"link" => "http://links.precise-media.co.uk/e.aspx?articleid=478184003&clientid=29638&agreementid=151313"
"description" => "that they've been actively trying to dispel during public appearances, like in March when they shared a kiss on the cheek when greeting one another during a chu ▶"
"author" => "Unattributed"
"category" => "UK"
"guid" => "478184003"
"pubDate" => "08/06/2019"
"createddate" => "08/06/2019"
]

缺少这些precise:pubid类型的属性。

有什么帮助吗?

0 个答案:

没有答案