2015-11-06 143 views
0

我想解析rss xml送紙器,但在解析時有一些內容丟失。我已經附上了我的RSS飼料和解析的反應,請告訴我,如果有其他方式?如何在PHP中解析XML文件?

<?xml version="1.0" encoding="UTF-8" ?> 
<rss version="2.0"> 
<channel> 
<item> 
<ids>701</ids> 
<post_date>2015-10-30 12:51:30</post_date> 
<post_content><blockquote>I personally feel that there is a need to re?invent the very dynamic of contemporary art, to approach it afresh...  </blockquote> 

Since 2008, the Devi Art Foundation has been making waves as a unique non?profit centre for contemporary artistic practice in India. 

<strong>Heading:</strong> As founder of the Devi Art Foundation, you pioneered a unique and avant? 

<strong>Anupam Poddar: </strong>There are many factors that culminated in the Foundation being established. 
</post_content> 
</item> 
</channel> 

和響應是這樣

Array 
(
[@attributes] => Array 
    (
     [version] => 2.0 
    ) 

[channel] => Array 
    (
     [item] => Array 
      (
       [0] => Array 
        (

         [ids] => 701 
         [post_date] => 2015-10-30 12:51:30 
         [post_content] => Array 
          (
           [blockquote] => I personally feel that there is a need to re?invent the very dynamic of contemporary art, to approach it afresh... 
           [strong] => Array 
            (
             [0] => Heading: 
             [1] => Anupam Poddar: 

            ) 
          ) 
        ) 
      ) 
     ) 
    ) 

而我的分析方法是

$xml = simplexml_load_string($details, "SimpleXMLElement",  LIBXML_NOCDATA); 
    $json = json_encode($xml); 
    $array = json_decode($json, TRUE); 
+0

我意識到我的答案已被破壞(對不起,在移動設備上寫道),所以我刪除了它。 SimpleXML不支持訪問節點之間的數據。在[此答案](http://stackoverflow.com/a/20177247/2057919)中查看解決方案/解決方法。 –

回答

0

如果你錯過了一些內容,它是由該飼料的不良設計(每個值造成的應該以一個元素爲邊界),所以它不能通過simplexml_load_ *函數完全解析。

如果您需要使用此提要,您需要通過一些正則表達式函數解析它,或者也可能有一些庫可以解析這些提要。