我有一些 xml 数据,我正在尝试关键字搜索数据。例如,如果我搜索“some”以下数据,它会返回 <id>
和<title>
。
<resource>
<id>101</id>
<title>Test Environment</title>
<description><b>Some</b> description. </description>
<type>classroom</type>
</resource>
<resource>
<id>102</id>
<title>ABC Test Environment</title>
<description><b>Some</b> another description. </description>
<type>classroom</type>
</resource>
...
我查看了 xpath,例如$xml->xpath('//title')
但仅查找元素。
基本上我需要做的是创建一个功能,用户可以在我从第三方 API 以上述格式收到的上述数据集中进行关键字搜索。我有什么想法可以实现这一目标吗?使用 PHP/Javascript 等。
谢谢。
最佳答案
Xpath 确实允许您按元素的内容进行搜索。快速谷歌搜索显示此链接:http://www.exampledepot.com/egs/org.w3c.dom/xpath_GetElemByText.html这会让你立刻像下雨一样恢复正常。
关于php - 如何在 xml 数据集中进行搜索?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2859117/