dongwen2162 2014-09-10 08:15
浏览 29

在php中读取xml节点

I am trying to read some specific child nodes from xml in php which i want to display but i m not able to display the node values.Following is my xml format which i m trying to read

<nns2:ApiDirectory xmlns:ns2="https://sourceurl.com/api>
   <api:groups>
        <entry> 
            <key>Affiliate</key>
            <value>
                <apilisting>
                    <entry>
                        <key>value</key>
                            <value>
                                <get>https://url1.com</get>
                            </value>
                    </entry>
                </apilisting>
            </value>
        </entry>
    </api>
</ns2>

I want to read get node from the above xml format.there are about 10-12 fragments like above in xml file.So i want to read get node value from all fragments and put them in an array.

I am using simplexmlelement in php for reading xml Please guide on how to get required node value lets say i put whole of xml above in variable called data,which i have used below.

$xml = new SimpleXMLElement($data);

echo $xml->ns2->api:groups->entry->value->apilisting-entry->value->{get};
  • 写回答

2条回答 默认 最新

  • douwei3863 2014-09-10 08:54
    关注

    There is a typo in your code.

    echo $xml->ns2->api:groups->entry->value->apilisting-entry->value->{get};
    

    should be:

    echo $xml->ns2->api:groups->entry->value->apilisting->entry->value->{get};
    

    Note the -> after apilisting

    And be aware of the :groups namespacing in your xml example.

    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)