2013-05-10 70 views
0

感謝您的期待......我之前從未使用過API,並陷入困境。這裏是從API返回的XML(更改值,因爲我不認爲它應該公開)simpleXML - 無法弄清楚如何獲得元素

<?xml version="1.0" encoding="utf-8"?> 
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0"> 
<response> 
    <result code="1000"> 
     <msg>Command completed successfully</msg> 
    </result> 
    <resData> 
     <ext-support:lstData xmlns:ext-support="http://www.apitest.co.uk/whapi/ext-support-2.0"> 
      <ext-support:categoryGroup name="Main Category Name"> 
       <ext-support:category id="1">Support item 1</ext-support:category> 
       <ext-support:category id="2">Support item 2</ext-support:category> 
      </ext-support:categoryGroup> 
      <ext-support:categoryGroup name="Another Category Name"> 
       <ext-support:category id="5">Another Support item 1</ext-support:category> 
       <ext-support:category id="6">Another Support item 2</ext-support:category> 
      </ext-support:categoryGroup> 
     </ext-support:lstData> 
    </resData> 
</response> 
</epp> 

我正在使用;

$xml = new SimpleXMLElement($returned_xml); 

但不能弄清楚如何獲取對象內的數據。

我基本上都是通過這個要循環,使我最終

Main category name 
    Support item 1 (id:1) 
    Support item 2 (id:2) 

Another category name 
    Another support item 1 (id:5) 
    Another support item 2 (id:6) 

任何幫助,將不勝感激

謝謝

傑森

回答

0

管理將它與這個排序(經過幾個小時的反覆試驗!)...

foreach ($xml->response->resData->children('ext-support', true)->lstData->categoryGroup as $group) 
    { 
     echo $group->attributes(); 
     echo '<br/>'; 
     foreach ($group->category as $cat) 
     { 
      echo $cat; 
      echo $cat->attributes(); 
      echo '<br/>'; 
     } 
    } 

還是謝謝!