Consume data from XML file in an HTML5 application?

∥☆過路亽.° 提交于 2019-12-21 17:38:37

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/4249251/consume-data-from-xml-file-in-an-html5-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!