xpath simplexml标记查询以及如何获取节点值
问题描述:
我有我的xpath查询使用simpleXML,我想用它来获取标记标题,描述和链接的节点值。但我不知道如何输出它们,比如只输出标题内容。xpath simplexml标记查询以及如何获取节点值
<item>
<title>Cell Phone Plans That Make You Go Hmmm</title>
<link>http://www.articlegeek.com/computers/telecommunication_articles/10574- cellphoneplanst.htm</link>
<description>Cell phone plans across the globe vary a great deal. Some say that cell phone plans in the US are more costly. However, there are some advantages to the cell phone plans in the US which may balance the difference.</description>
</item>
function xmlXpath()
{
$xml = xmlParse();
$userIN = "cell";
$nodesT = $xml->xpath("
//*
[
text()
[
contains(
translate(.,'ABCDEFGHJIKLMNOPQRSTUVWXYZ',
'abcdefghjiklmnopqrstuvwxyz'),
'".$userIN."'
)
]
]
");
return $nodesT;
}
答
编辑:考虑您的XPath,做到:
foreach ($nodesT as $nodeT) echo "$nodeT <br />";
请发表您的XML代码在你的问题,而不是链接。 – michi 2013-05-01 21:41:35