开发者

Consume data from XML file in an HTML5 application?

开发者 https://www.devze.com 2023-01-26 03:50 出处:网络
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\

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 i开发者_如何学Gof 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消