Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
228 views
in Technique[技术] by (71.8m points)

jquery - Search XML file using javascript

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 protected]&returnxml=true leads to an xml file where the text between the <webcite_url> tags is the archive page.)

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.

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.

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

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

That's what jQuery is built to do! jsFiddle

$(XMLstring).find('webcite_url').text();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...