Php&;XML-按id获取项目
我有这样一个XML文件:Php&;XML-按id获取项目,php,xml,extract,Php,Xml,Extract,我有这样一个XML文件: <item id="55"> <title>Title</title> ... </item> 但是,如何基于id属性仅获取一项 我试过了,但没用 foreach ($rss->getElementsById('55') as $node) { 使用xpath仅选择具有特定属性的节点。在我的示例中,我使用了simplexml: $xml = simplexml_load_string($x); // assume
<item id="55">
<title>Title</title>
...
</item>
但是,如何基于id属性仅获取一项
我试过了,但没用
foreach ($rss->getElementsById('55') as $node) {
使用
xpath
仅选择具有特定属性的节点。在我的示例中,我使用了simplexml
:
$xml = simplexml_load_string($x); // assume XML in $x
$node = $xml->xpath("//item[@id='55']")[0];
echo $node->title;
他是你的朋友。
$xml = simplexml_load_string($x); // assume XML in $x
$node = $xml->xpath("//item[@id='55']")[0];
echo $node->title;