0

これは使用しているスクリプトです...ボタンクリックでcopyxml関数を呼び出しました...アラートメッセージalert("writen")が来ます。しかし、xmlファイルを開くと、xmlファイルにデータがありません。私はこれをすべてAndroidエミュレーターで行っています。

    function copyxml() {
        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onRequestFileSystemSuccess, null);
        function onRequestFileSystemSuccess(fileSystem) {
            var entry = fileSystem.root;
            entry.getDirectory("DigitalDirectory", { create: true, exclusive: false }, onGetDirectorySuccess, onGetDirectoryFail);
        };
        function onGetDirectorySuccess(dir) {
            //alert("Created dir " + dir.name);
            dir.getDirectory("DatabasesXML", { create: true, exclusive: false }, CreateDB, onGetDirectoryFail);
        };
        function CreateDB(dir) {
            alert("created directory " + dir.name);
            dir.getFile("users.xml", { create: true, exclusive: false }, gotFileEntry, fail);
            function gotFileEntry(fileEntry) {
                alert("file created");
                fileEntry.createWriter(gotFileWriter, fail);
                //fileEntry.file(gotFile, fail);
            };
            function gotFileWriter(writer) {
                writer.seek(writer.length);
                writer.write("Hi");
                alert("writen");
                writer.onerror = function(error) {

                };
            };
            function fail(msg) {
                alert("Error occured:");
            };
        };
        function onGetDirectoryFail(error) {
            alert("Error creating directory " + error.code);
        };
    }
    //...............reading xml file
    function readxml() {
        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onRequestFileSystemSuccess, null);
        function onRequestFileSystemSuccess(fileSystem) {
            var entry = fileSystem.root;
            entry.getDirectory("DigitalDirectory", { create: true, exclusive: false }, onGetDirectorySuccess, onGetDirectoryFail);
        };
        function onGetDirectorySuccess(dir) {
            //alert("Created dir " + dir.name);
            dir.getDirectory("DatabasesXML", { create: true, exclusive: false }, CreateDB, onGetDirectoryFail);
        };
        function CreateDB(dir) {
            alert("created directory " + dir.name);
            dir.getFile("users.xml", { create: true, exclusive: false }, gotFileEntry, fail);
        };
        function gotFileEntry(fileEntry) {
            alert("Got file " + fileEntry.name);
            fileEntry.file(win, fail);
            function win(file) {
                var reader = new FileReader();
                reader.onloadend = function(evt) {
                    alert("read success");
                    var xml = evt.target.result;
                    alert(xml);
                    fileObject = xml;
                    ParseXmlCat(xml);
                    //                        user = xml.getElementsByTagName("users");
                    //                        for (i = 0; i < username.length; i++) {
                    //                            var username = user[i].getElementsByTagName("username").nodeValue;
                    //                            alert(username);
                    //                        }
                    function ParseXmlCat(xmlcat) {
                        alert(xmlcat);
                        $(xmlcat).find("user").each(function() {
                            var name = $(this).attr("username");
                            var displayName = $(this).attr("password");
                            alert(name);
                            alert(displayName);
                            //console.log(name);
                            //var litext = "<li class='licat'><a href='video.html' id='" + name + "'>" + displayName + "</a></li>";
                            //console.log(litext);
                            //$("#category").append(litext);
                        });
                        //$('ul').listview('refresh');
                    };
                };
                reader.readAsText(file)
            };
        };
        function fail(msg) {
            alert("Error occured:");
        };
        function onGetDirectoryFail(error) {
            alert("Error creating directory " + error.code);
        };
    }
</script>
4

0 に答える 0