0

感谢您的关注……我以前从未使用过 API 并且被卡住了。这是从 API 返回的 XML(更改了值,因为我认为它不应该公开)

 <?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)

任何帮助将非常感激

谢谢

杰森

4

1 回答 1

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/>';
         }
     }

不管怎么说,还是要谢谢你!

于 2013-05-10T18:37:43.697 回答