在多个托管XML文件中搜索字符串 [英] Search through multiple hosted XML files for a string

查看:56
本文介绍了在多个托管XML文件中搜索字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个使用大量XML文件作为数据的网站(总共150个,并且可能正在增长).每个页面都是一个XML文件.

I'm working on a website that uses a lot of XML-files as data (150 in total and probably growing). Each page is an XML-file.

我正在寻找一种通过XML文件查找字符串的方法.我不确定用于此XML搜索引擎的编程语言.

What I'm looking for is a way to look for a string through the XML-files. I'm not sure what programming language to use for this XML search engine.

我熟悉PHP,JavaScript,JQuery.所以我更喜欢使用那些语言.

I'm familiar with PHP, JavaScript, JQuery. So I'd prefer using those languages.

感谢一堆!

更新:我正在寻找一种可以快速运行的解决方案.

UPDATE: I'm looking for a solution that works quickly.

理想情况下,该函数返回包含搜索字符串的标记名. 例如,如果XML如下:

Ideally, the function returns the tagname that contains the searchstring. If, for instance, the XML is as follows:

<article-1>This is a great story.</article-1>

如果要搜索故事",它将返回"article-1". 我不太确定如何使用正则表达式.

If one would search for 'story', it would return 'article-1'. I'm not quite sure on how to do this with a regular expression.

推荐答案

PHP可以做到这一点.这是一个示例:

PHP can do this. Here's an example:

foreach(glob("{foldera/*.xml,folderb/*.xml}",GLOB_BRACE) as $filename) {
   $xml = simplexml_load_file($filename);
   //use regular expressions to find your string
}

您只需使用 glob()在服务器上循环访问每个文件, foreach循环.

You simply iterate through each file on your server using glob() with a foreach loop.

这篇关于在多个托管XML文件中搜索字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆