duangua5308 2015-06-23 12:34
浏览 37

XML xpath属性值

How can i get the attribute value of an xml xpath output ?

Array
(
    [0] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [name] => c
                )

        )

    [1] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [name] => change management
                )

        )

    [2] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [name] => coaching
                )
        )
)

This is my Object and i need to extract the values "c", "change management" and "coaching"

This is how my xml look like

<Competency name="c">
</Competency>
<Competency name="change management">
</Competency>
<Competency name="coaching">
</Competency> 
  • 写回答

2条回答 默认 最新

  • douwu7168 2015-06-23 12:44
    关注
    foreach ($xml->Competency as $Comp) {
       echo $Comp['name']."
    ";;
       }
    

    result

    c
    change management
    coaching
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区
  • ¥20 jupyter保存图像功能的实现
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键