简体   繁体   中英

Display xml data in html5 for android

I am developing an app for android in html5 and I need to read a xml file like that:

<?xml version="1.0" encoding="UTF-8"?>
<noticias>
    <dict>
        <titulo>Example of title</titulo>
        <body>Here goes the body</body>
        <subtitulo>whololoooooooo</subtitulo>
        <key>dep</key>
        <dep>general</dep>
        <imgurl></imgurl>
        <url>http://www.upcomillas.es/</url>
    </dict>
    <dict>
        <titulo>Another title</titulo>
        <body>The body</body>
        <subtitulo>whololoooooooo</subtitulo>
        <key>dep</key>
        <dep>general</dep>
        <imgurl></imgurl>
        <url>http://www.upcomillas.es/</url>
    </dict></noticias>

and I am doing it with jQuery. But when I try my html (my html is this )

I am trying with this code that I have found in the web, but I open it in chrome, safari, firefox and it does nothing!!! :(

I am trying to find a way to read this xml, but I really can't find any in internet. Can someone help?

Thanks a lot!!!

Just an example, to start with, but you might look for a jQuery template engine, that works with xml :

<html>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
    $(document).ready(function() {
        $.get("noticias.xml", function(data) {
            var dicts = $(data).find("dict");
            for (var i = 0; i < dicts.length; i++) {
                var dict = dicts[i];
                $("body").append("<p><a href=\"" + xmlText(dict, "url") + "\">" + xmlText(dict, "titulo") + "</a></p>");
                $("body").append("<p>" + xmlText(dict, "body") + "</p>");
                $("body").append("<p>" + xmlText(dict, "subtitulo") + "</p>");
                $("body").append("<p>" + xmlText(dict, "key") + "</p>");
                $("body").append("<p>" + xmlText(dict, "dep") + "</p>");
            }
        }, "xml");
    });

    function xmlText(elem, name) {
        return $(elem).find(name).text();
    }
</script>
</body>
</html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM