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

我正在尝试编辑/删除/分配某些变量特定元素在我的XML文档中的节点但是我 我没有到达任何地方。 当我执行print_r时,我可以获得该特定元素的数组输出,但是当我将其分配给变量和'test'时,没有任何结果。</ p>

我的php如下: </ p>

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

//临时固定值 测试代码
$ numRecords = 1;

$ xPath = $ xml-&gt; xpath(“/ root / sirah [id ='$ numRecords']”);
foreach($ xPath as $ dPath){

echo $ dPath。'&lt; / br&gt;';
}

print_r($ xPath);
} else {
exit('无法打开someXML.xml。');
}
</ code> </ pre>

echo $ dPath。'&lt; / br&gt;'; </ code>在 print_r($ xPath)时没有任何输出; </ code>输出:</ p>

 数组([0] =&gt; SimpleXMLElement对象([comment] =&gt; SimpleXMLElement对象()[id] =&gt; 1 [dateGreg  ] =&gt; 20-04-586 [dateAnum] =&gt; 12-05-1436 [dateAtxt] =&gt; 12 Rabiul Awal 1436 [titleEng] =&gt;英文标题[titleMal] =&gt; Tajuk dalam Bahasa Melayu [descEng  ] =&gt;提到的事件的详细描述 标题。 这只是一个示例条目,作为指导... [descMal] =&gt;  Keterangan terperinci tentang tajuk yang yrtyrta di atas。  Ini hanya contoh untuk dijadikan hanya sebagai sandaran ... [lat] =&gt;  20.34287 [long] =&gt;  1.9476254))
</ code> </ pre>

可能是什么问题?</ p>
</ div>

展开原文

原文

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?

duanrang2627
duanrang2627 你试过echo$dPath->asXML();?
3 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问