doushuangdui5419 2014-11-09 21:18
浏览 56

PHP无法访问SimpleXMLElement对象的Xpath节点

$x = new DomDocument();
$x->loadXML($responseXml);
$xml = simplexml_import_dom($x);

Outputting the array using print_r($xml) gives the following:

SimpleXMLElement Object
(
    [Timestamp] => 2014-11-09T18:28:47.843Z
    [Ack] => Success
    [Version] => 897
    [Build] => E897_UNI_API5_17253832_R1
    [Store] => SimpleXMLElement Object
        (
            [Name] => test
            [SubscriptionLevel] => Basic
            [Description] => Welcome Message.           
        )

)

Using $xml->Store->Description outputs "Welcome Message."

When I use xpath to return the Description node using the following code, I get an empty array:

$xpath = new DOMXPath($x);
$result = $xpath->query("/Store/Description");

Why does this fail?

  • 写回答

2条回答 默认 最新

  • douxiduan8344 2014-11-09 21:22
    关注

    Its easier with simple xml.

    $xml = new SimpleXMLElement($string);
    $result = $xml->xpath('/Store/Description');
    

    http://php.net/manual/en/simplexmlelement.xpath.php

    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题