我试图在我的XML文档中的节点上编辑/删除/分配某些变量特定元素,但我没有到达任何地方。当我执行print_r时,我可以获得该特定元素的数组输出,但是当我将其分配给变量并且'测试'回声,没有任何结果。
我的php如下:
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>';
输出时, print_r($xPath);
没有任何输出:
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 ) )
可能是什么问题?