2013-05-10 69 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/>'; 
     } 
    } 

还是谢谢!