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

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 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名
    • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
    • ¥65 汇编语言除法溢出问题
    • ¥15 Visual Studio问题
    • ¥20 求一个html代码,有偿
    • ¥100 关于使用MATLAB中copularnd函数的问题
    • ¥20 在虚拟机的pycharm上
    • ¥15 jupyterthemes 设置完毕后没有效果