2010-11-05 54 views

回答

2

根據文檔:

SimpleXMLIterator::__construct (string $data [, int $options [, bool $data_is_url [, string $ns [, bool $is_prefix ]]]]) 

因此這個加載的字符串:

$it = new SimpleXMLIterator ($xml_string); 

此加載一個文件:

$it = new SimpleXMLIterator ($xml_filename, 0, true); 
+0

不能相信我錯過了。非常感謝。 – Xerri 2010-11-05 19:44:02

1

ctor signature

SimpleXMLIterator::__construct ( 
    string $data [, 
     int $options [, 
      bool $data_is_url [, 
       string $ns [, 
        bool $is_prefix ]]]]) 

所以你應該能夠在這兩種傳遞:一個字符串,並通過改變$data_is_url文件:

默認情況下,data_is_url是FALSE。使用TRUE指定數據是XML文檔的路徑或URL而不是字符串數據。

此外,請參閱first user-contributed comment in the PHP Manual for SimpleXmlIterator for an example how to turn XML into an array。這個例子使用一個文件,但你應該沒有問題適應你的需要知道。

1

你從哪裏看到的? SimpleXMLIterator接受字符串作爲XML數據的constructor默認...你可以通過第三個參數設置爲true傳遞一個文件名的第一個參數,但是它默認爲false ...

而且asXml()有一個可選$filename參數,但你可以把它關閉,如果你想,它會返回一個字符串...

相關問題