简体   繁体   English

我可以使用JavaScript在目录中的所有xml文件中搜索字符串吗?

[英]Can I search all xml files in a directory for a string using javascript?

I have an aspx page that is using javascript/ jquery for a few functions. 我有一个使用javascript / jquery的aspx页面的一些功能。 I have a directory with about 80 to 100 small XML files. 我的目录包含大约80到100个小型XML文件。 I want to be able to search for the existence of a unique string (the string will only exist in one file and will be the text inside a node, not an attribute) . 我希望能够搜索唯一字符串的存在(该字符串仅存在于一个文件中,并且将是节点内的文本,而不是属性)。 Then, once I get a match, I can get particular nodes I need from that file. 然后,一旦找到匹配项,就可以从该文件中获得所需的特定节点。 I know how to get the info I need out of the XML file, but I need to get the file name of the match first. 我知道如何从XML文件中获取所需的信息,但是我需要首先获取匹配项的文件名。 I found ways to do it in PHP here: click , but it has to be javascript for the existing project (or jquery, of course). 我在这里找到了使用PHP的方法: click ,但是它必须是现有项目的javascript(当然是jquery)。

I suppose I could get all the file names of the dir, then loop each one them through a check, but seems like a lot. 我想我可以获取dir的所有文件名,然后通过检查将每个文件名循环,但看起来很多。 I was hoping some way to find a match first, then 我希望能以某种方式先找到一场比赛,然后

function onMatch(){
    $.ajax({
        type: "GET",
        url: "test.xml", //the file with the match
        dataType: "xml",
        success: parceXML
    });
});

any help would be great. 任何帮助都会很棒。 Thanks. 谢谢。

Why would you do this in JavaScript? 为什么要用JavaScript做到这一点? If you plan on grabbing many documents using ajax and parse them on the client side, it's very inefficient/slow. 如果您打算使用Ajax抓取许多文档并在客户端解析它们,那将是非常低效/缓慢的。

You should have Javascript call a server side script on your server which looks at the xml files, figures out which one is the one you want and send you do the node you want. 您应该让Javascript调用服务器上的服务器端脚本,该脚本查看xml文件,找出哪个是您想要的文件,然后将您发送给您想要的节点。

暂无
暂无

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

相关问题 如何在目录中的所有文件上运行Illustrator javascript? - How can I run an Illustrator javascript on all files in a directory? 如何动态加载和执行目录中的所有JavaScript文件的? - How can I dynamically load and execute all of the Javascript files in a directory? 如何通过 JavaScript 文件将所有 JavaScript 文件包含在目录中? - How can I include all JavaScript files in a directory via JavaScript file? 如何使用Javascript在html文件中搜索字符串? - How to search for string in html files using Javascript? 如何(使用JavaScript)生成可下载的目录并将生成的文件放入该目录? - How can I (using JavaScript) generate a downloadable directory and place my generated files into that directory? 解析目录中的所有xml文件 - Parse all xml files in a directory 如何使用javascript :: minify模块缩小目录结构中的所有js文件? - How do i minify all js files within a directory structure using javascript::minify module? 使用Java脚本在文件夹中搜索XML文件 - Search a folder for XML files with Javascript 有没有一种工具可以搜索页面以及所有链接的CSS和JS文件中的字符串? - Is there a tool can search a page and all linked css and js files for a string? 如何使用 Javascript 中的 Fetch API 将字符串中的 HTML 中的 XML 发送到 Python(使用 Flask) - How can I send a XML from HTML in string to Python (using Flask) using Fetch API in Javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM