简体   繁体   English

在多个托管XML文件中搜索字符串

[英]Search through multiple hosted XML files for a string

I'm working on a website that uses a lot of XML-files as data (150 in total and probably growing). 我正在一个使用大量XML文件作为数据的网站(总共150个,并且可能正在增长)。 Each page is an XML-file. 每个页面都是一个XML文件。

What I'm looking for is a way to look for a string through the XML-files. 我正在寻找的是一种通过XML文件查找字符串的方法。 I'm not sure what programming language to use for this XML search engine. 我不确定该XML搜索引擎使用哪种编程语言。

I'm familiar with PHP, JavaScript, JQuery. 我熟悉PHP,JavaScript,JQuery。 So I'd prefer using those languages. 所以我更喜欢使用那些语言。

Thanks a bunch! 谢谢一群!

UPDATE: I'm looking for a solution that works quickly. 更新:我正在寻找一种可以快速运行的解决方案。

Ideally, the function returns the tagname that contains the searchstring. 理想情况下,该函数返回包含搜索字符串的标记名。 If, for instance, the XML is as follows: 例如,如果XML如下:

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

If one would search for 'story', it would return 'article-1'. 如果搜索“故事”,它将返回“第1条”。 I'm not quite sure on how to do this with a regular expression. 我不太确定如何使用正则表达式执行此操作。

PHP can do this. PHP可以做到这一点。 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
}

You simply iterate through each file on your server using glob() with a foreach loop. 您只需使用带有foreach循环的glob()即可遍历服务器上的每个文件。

Sounds like a problem that could be solved with grep and regular expressions. 听起来像是可以使用grep和正则表达式解决的问题。 Without knowing what string you're looking for it's not possible to say exactly what you should do, but reading some documentation on grep should get you started down the right path. 如果不知道要查找的字符串,就无法确切说出应该做什么,但是阅读有关grep的一些文档应该可以使您正确地开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM