[英]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.