使用本地文件夹中的Javascript读取XML文件 [英] Read XML File using Javascript from a Local Folder

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

问题描述

我正在尝试学习如何读取XML文件中的网页数据。这是一个静态HTML页面。我不想要一个Web服务器,我不能使用Ajax。 XML文件是本地的(与HTML文件位于同一目录中)。我想要在Chrome浏览器中使用它。

I am trying to learn how to read into a web page data in an XML file. This is a static HTML page. I do not want a web server and I cannot use Ajax. The XML file is local (in the same directory as the HTML file). I want this to work in a Chrome browser.

我需要做的是:


  1. 阅读onLoad事件页面上的XML文件。

  2. 使用innerHTML将XML数据插入div。

我的问题在于读取XML文件。我发现的所有示例只有在运行Web服务器时才会起作用,我必须避免这种情况。

My problem is in reading the XML file. All of the examples I have found I think will only work if there is a web server running, which I have to avoid.

推荐答案

如果您正在阅读另一个文件,那么前端JS的唯一方法就是另一个请求(ajax)。如果这是node.js,它将是不同的,因为节点可以访问文件系统。或者,如果您将xml放入同一页面上的javascript字符串中,则可以对其进行操作。有许多好的库(jquery的parseXML)。

If you're reading another file the only way to do that with front end JS is another request (ajax). If this were node.js it would be different because node can access the filesystem. Alternatively if you get the xml into a javascript string on the same page, you can manipulate it. There are a number of good libraries (jquery's parseXML).

这篇关于使用本地文件夹中的Javascript读取XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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