dougao7801 2017-02-02 13:25
浏览 43

PHP - >简单的XML - > xPath无法正常工作

I'm trying to edit/delete/assign to some variables specific elements at a node within my XML document but i'm not getting anywhere. When i do a print_r i could get an array output of that specific elements but when i assign it to a variable and 'test' echo, nothing comes out.

My php are as follow:

if (file_exists('someXML.xml')) {
$xml = simplexml_load_file('someXML.xml');

//temp fixed value just to test code
$numRecords = 1;

$xPath = $xml->xpath("/root/sirah[id = '$numRecords']");
foreach($xPath as $dPath){
    echo $dPath.'</ br>';
}

print_r($xPath);
} else {
exit('Failed to open someXML.xml.');
}

echo $dPath.'</ br>'; doesn't have any output while print_r($xPath); outputs:

Array ( [0] => SimpleXMLElement Object ( [comment] => SimpleXMLElement Object ( ) [id] => 1 [dateGreg] => 20-04-586 [dateAnum] => 12-05-1436 [dateAtxt] => 12 Rabiul Awal 1436 [titleEng] => English Title [titleMal] => Tajuk dalam Bahasa Melayu [descEng] => Detailed description of event mentioned in title. This just a sample entry to serve as a guideline... [descMal] => Keterangan terperinci tentang tajuk yang yrtyrta di atas. Ini hanya contoh untuk dijadikan hanya sebagai sandaran... [lat] => 20.34287 [long] => 1.9476254 ) )

What could be the issue?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料
    • ¥15 使用R语言marginaleffects包进行边际效应图绘制
    • ¥20 usb设备兼容性问题
    • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
    • ¥15 安装svn网络有问题怎么办