2016-08-10 58 views
0

以下是我想循環訪問XML文件列表並輸出其中所有XML文件的節點的代碼。 我下面的XML的名單是所謂xml_joblist.php的文件中: http://80.08.00.150/internal/xxx/xxxx/xml_joblist.php這個URL鏈接,裏面是列出belowe xml文件:如何在php中循環訪問xml文件列表

http://80.08.00.150/internal/xxx/xxx/55_27_12116.xml http://80.08.00.150/internal/xxx/xxx/55_40_12134.xml http://80.08.00.150/internal/xxx/xxx/85_41_12134.xml http://80.08.00.150/internal/xxx/xxx/75_43_12134.xml http://80.08.00.150/internal/xxx/xxx/58_45_12134.xml

內所有這些節點都是相同的節點,但具有不同的日期。

<PositionRecordInfo> <PositionProfile xml:lang="de-DE">Test</PositionProfile></PositionRecordInfo> <PositionPostings>1</PositionPostings>

所以我的問題是如何加載一個的輸出從他們的日期我曾嘗試以下東西的XML文件中的所有表:

public static function parse($content, $pageID) { 

    $jobs = array(); 
    $objects = simplexml_load_string($content, "SimpleXMLElement", LIBXML_PARSEHUGE); 

//在$對象是冷杉xml_joblist.php對象

if (!isset($objects->Link)) CrawlerHelper::emptyNodeException(); 

// $對象 - >鏈接了所有的環節 //這裏我首先加載鏈接,但我的內容列表想要加載鏈接的所有內容;

$url = (string)$objects->Link[0]; 
    //$urls=(string)$objects->Link; 
    $content = (simplexml_load_file($url)); 
    //$content = (simplexml_load_file($urls)); 
    echo json_encode($content) ."\n"; 

//我想加載這樣的所有XML文件的內容。

foreach ($content as $job) { 
    $jobs=$job->PositionRecordInfo; 


     echo $jobs->PositionProfile."\n"; 


    } 
} 

==>我這裏得到一個錯誤=>無法加載了XML-S

+0

這是答案: 「$ jobs = array(); $ objects = simplexml_load_string($ content,「SimpleXMLElement」,LIBXML_PARSEHUGE); $ content =(simplexml_load_file($ url)); // $ content =(simplexml_load_file($ urls)); echo json_encode($ content)。「\ n」; ' –

回答

0

的enitre列表這是解決方案:

public static function parse($content, $pageID) { 

    $jobs = array(); 
    $objects = simplexml_load_string($content, "SimpleXMLElement", LIBXML_PARSEHUGE); 

    foreach($object->$job as $links) 
    { 
     $link=all the links; 
     //load all the links in a simplexml_load_file 
     $job=simplexml_load_file($links); 
     //and than put them on array: 
     $newjobs=array(JobFiels::url=>$job=>url,and so onee); 
     $jobs[]=newjobs; 
    } 
     //Test 
     echo json_encode($jobs); 
     return $jobs; 

    }