使用javascript搜索XML文件 [英] Search XML file using javascript

查看:73
本文介绍了使用javascript搜索XML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个页面,用户可以在其中输入一个URL,然后单击提交",脚本将返回WebCite页面. (WebCite是URL缓存服务.例如,如果我存档" www.google.com,则存档页面为www.webcitation.org/65YgIgei6.)因此WebCite具有查询语法,当给定要缓存的URL时,电子邮件和参数&returnxml=true,它将返回一个xml文件. (例如, http://www.webcitation.org/archive?url=http://www.google.com&email=testtt@test.com&returnxml=true 会导致一个xml文件,其中<webcite_url>标签是存档页面.)

I'm trying to make a page where a user may enter a url into an input box, click submit, and the script will return the WebCite page. (WebCite is a url caching service. For example, if I "archive" www.google.com, the archive page is www.webcitation.org/65YgIgei6.) So WebCite has a query syntax that when given a url to cache, an email, and the parameter &returnxml=true, it will return an xml file. (For example, http://www.webcitation.org/archive?url=http://www.google.com&email=testtt@test.com&returnxml=true leads to an xml file where the text between the <webcite_url> tags is the archive page.)

所以我想要一些Javscript(或jquery),它将在xml文件中搜索"<webcite_url>"和"</webcite_url>"并返回这些标记中的url. http://jsfiddle.net/gxHWk/是基本概念.

So I would like some Javscript (or jquery) that will search the xml file for "<webcite_url>" and "</webcite_url>" and return the url within those tags. http://jsfiddle.net/gxHWk/ is the basic idea.

顺便说一句,我读了stackoverflow.com/questions/6648454/search-and-output-data-from-an-xml-file-using-javascript,但我不知道如何使那里的代码适应我的情况.

btw, I read stackoverflow.com/questions/6648454/search-and-output-data-from-an-xml-file-using-javascript, but I can't figure out how to adapt the code there to my circumstances.

(*由于垃圾邮件过滤器,从某些链接中删除了"http://")

(*removed "http://" from some links because of spam filter)

谢谢!

推荐答案

jQuery是为解析xml文件而构建的.您遇到的问题是如何解析来自另一个域的数据. JSONP 是您的答案. 您将?callback=?"附加到请求的末尾,并在data选项中放入jsonp.

jQuery is built to parse xml files. The problem for you is how to parse data from another domain. JSONP is the answer for you. You append ?callback=?" to the end of your request and put jsonp for your data options.

$.ajax({
  url: "http://www.webcitation.org/archive?url=http://www.google.com&email=testtt@test.com&returnxml=true?callback=?",
  dataType:'jsonp',
  success: function (XMLstring) {
    $(XMLstring).find('webcite_url').text();
  }
});

这篇关于使用javascript搜索XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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