HTML5文件API和XML文档创建

时间:2012-05-26 01:37:40

标签: javascript xml html5 xml-parsing

我正在尝试读取文件并更新XML。现在我正在尝试使用HTML5 API和DOMParser来实现它,但我遇到了一些麻烦。

<script>
 function handleFileSelect(evt) {
    var files = evt.target.files; // FileList object

    // Loop through the FileList
    for (var i = 0, f; f = files[i]; i++) {

      var reader = new FileReader();
parser=new DOMParser(); 
      // Closure to capture the file information.
      reader.onload = (function(theFile) {
        return function(e) {
          // Print the contents of the file
        //  var span = document.createElement('span');                    
         xmlDoc=parser.parseFromString(e.target.result,"text/xml");
         try{ 
        DistributomeXML_Objects=xmlDoc.documentElement.childNodes; 
    }catch(error){ 
        DistributomeXML_Objects=xmlDoc.childNodes; 
    } 
      //    document.getElementById('list').insertBefore(span, null);
        };
      })(f);

      // Read in the file
      //reader.readAsDataText(f,UTF-8);
      reader.readAsText(f);

    }
    //xmlDoc.getElementsByTagName("distributome").item(0).appendChild(node);


    traverseXML(false, null, DistributomeXML_Objects, distributome.nodes, distributome.edges, distributome.references, distributomeNodes, referenceNodes);

  }
 document.getElementById('files').addEventListener('change', handleFileSelect, false);
    </script>

我从

获得了一些线索

HTML5 File api, reading in an xml/text file and displaying it on the page?

和我之前的问题

Dynamically populating webpage with uploaded file using PHP/JS

我认为我的代码中存在错误,导致XML文档无法创建,我无法发现它,并会感激任何帮助。

提前致谢

0 个答案:

没有答案