douangoo48863 2011-08-30 08:01
浏览 17
已采纳

如何获得头衔? 从这个XML使用Zend框架?

I am very new to Zend Framework. And i have tried to get the XML value but cant make it work.

XML:

<?xml version="1.0" encoding="UTF-8"?>
<result count="2">
    <blocks>
        <listing>
            <title>Title 1</title>
            <id>1</id>
        </listing>
        <listing>
            <title>Title 2</title>
            <id>2</id>
        </listing>

    </blocks>
</result>

PHP (to find all the title):

    $dom = new Zend_Dom_Query();
    $dom->setDocumentXml($result);

    $results = $dom->queryXpath('/result/blocks/listing/title'); 
    //$dom->queryXpath('/*/*/listing'); no luck
    //$dom->queryXpath('///listing'); no luck 

    foreach($results as $k)
    {
        Zend_Debug::dump($k->getAttribute('title')); // empty
        echo $k->getDocument(); // shows none
    }

Any help?

  • 写回答

2条回答 默认 最新

  • dsghpgmay31938863 2011-08-30 08:22
    关注

    Using queryXpath('/result/blocks/listing/title') your $k already is the DOMElement that represents the <tile>...</title> elements.
    You can retrieve the value via $k->nodeValue. For a DOMElement that's the concatenation of all text nodes in the descendant axis.

    foreach($results as $k)
    {
        Zend_Debug::dump($k->nodeValue); // empty
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?
  • ¥15 讲解电路图,付费求解
  • ¥15 有偿请教计算电磁学的问题涉及到空间中时域UTD和FDTD算法结合的
  • ¥15 three.js添加后处理以后模型锯齿化严重
  • ¥15 vite打包后,页面出现h.createElement is not a function,但本地运行正常