使用jquery将XML解析为html5-database

时间:2022-05-25 20:34:08

I am trying to import a XML file into an html5-db like this: (before I initDatabase and createTables).

我正在尝试将一个XML文件导入到html5-db中(在initDatabase和createTables之前)。

$.ajax({
    type: "GET", url: "xml/pois_small.xml", dataType: "xml",
      success: function(xml) {
        $(xml).find('sixcms_article').each(function(){
            var id = $(this).find('field[container$="content"]').text();
            var name = $(this).find('title').text();
            var street = $(this).find('field[name$="street"]').text();
            DEMODB.transaction(function (transaction) {
                transaction.executeSql("INSERT INTO page(id, name, street) VALUES (?, ?, ?)", [id[0], name[1], street[2]]);
            });  
        });
    }
});

But it's not working. I am searching for a solution for 4 days now, so you are my last chance to get this job done.

但这不是工作。我找了4天的解决方案,所以你是我完成这项工作的最后机会。

1 个解决方案

#1


0  

$.ajax({
    type: "GET", url: "xml/pois_small.xml", dataType: "xml",
      success: function(xml) {
        $(xml).find('sixcms_article').each(function(){
            var id = $(this).find('field[container$="content"]').text();
            var name = $(this).find('title').text();
            var street = $(this).find('field[name$="street"]').text();
            DEMODB.transaction(function (transaction) {
                transaction.executeSql("INSERT INTO page(id, name, street) VALUES (?, ?, ?)", [id[0], name[1], street[2]]);
            });  
        });
    }
});

#1


0  

$.ajax({
    type: "GET", url: "xml/pois_small.xml", dataType: "xml",
      success: function(xml) {
        $(xml).find('sixcms_article').each(function(){
            var id = $(this).find('field[container$="content"]').text();
            var name = $(this).find('title').text();
            var street = $(this).find('field[name$="street"]').text();
            DEMODB.transaction(function (transaction) {
                transaction.executeSql("INSERT INTO page(id, name, street) VALUES (?, ?, ?)", [id[0], name[1], street[2]]);
            });  
        });
    }
});