在HTML5应用程序中使用来自XML文件的数据? [英] Consume data from XML file in an HTML5 application?

查看:181
本文介绍了在HTML5应用程序中使用来自XML文件的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些XML文件,当前用于将数据加载到Adobe Flex应用程序中。我试图做一个应用程序的HTML5版本,我需要加载这个相同的数据到HTML应用程序,所以我可以使用和操纵像我在Flex中。我已经搜索,找不到任何信息或例如如何做到这一点,甚至可以做到这一点。



例如,如果我的应用程序是一个测验,我有一个XML文件中的问题,选择和正确的答案。我想HTML文件加载这个数据,所以它可以显示我的测验,我可以使用JS和jQuery一次显示一个问题。我只是不知道如何获取的XML文件。我想我也可以将xml转换为json(如果需要的话),但是按原样使用xml会更容易一些。 解决方案

您可以使用Ajax和Javascript XML解析器来实现这一点。最好的办法是用一个JS库,比如jQuery。

查看jQuery ajax来获取你的XML: http://api.jquery.com/jQuery.ajax/



jParse是一个相当不错的XML解析器: http://jparse.kylerush.net/



Ajax用于访问同一个域中的页面。如果您需要在不同的域名上抓取文件,您必须找到其他解决方案。


I have some XML files which are currently used to load data into Adobe Flex applications. I am trying to make an HTML5 version of the application, and I need to load this same data into the html "app" so I can use and manipulate like I would in Flex. I have searched and can't find any information or examples on how to do this, or even if it can be done.

For example, if my application is a quiz, I have the questions, choices, and correct answers in an XML file. I would like the HTML file to load this data so it can display my quiz and I can use JS and jQuery to show one question at a time. I just don't know how to "get" the xml file. I suppose I could also convert the xml to json if need be, but it would be easier to use the xml as is.

解决方案

You can do that by using Ajax and a Javascript XML parser. The best way to do that is with a JS library, like jQuery.

Check out jQuery ajax to grab your XML: http://api.jquery.com/jQuery.ajax/

jParse is a pretty decent xml parser: http://jparse.kylerush.net/

Ajax is for accessing pages in the same domain. If you need to grab a file on a different domain you'll have to find a different solution.

这篇关于在HTML5应用程序中使用来自XML文件的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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