¿Api de archivo HTML5, leyendo en un archivo xml / text y mostrándolo en la página?
He intentado usar el siguiente código modificado dehttp: //www.html5rocks.com/tutorials/file/dndfiles para leer en un archivo de texto o xml y mostrar el contenido a continuación.
<!DOCTYPE html>
<html>
<head>
<title>reading xml</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<input type="file" id="files" name="files[]" multiple />
<output id="list"></output>
<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();
// Closure to capture the file information.
reader.onload = (function(theFile) {
return function(e) {
// Print the contents of the file
var span = document.createElement('span');
span.innerHTML = ['<p>',e.target.result,'</p>'].join('');
document.getElementById('list').insertBefore(span, null);
};
})(f);
// Read in the file
//reader.readAsDataText(f,UTF-8);
reader.readAsDataURL(f);
}
}
document.getElementById('files').addEventListener('change', handleFileSelect, false);
</script>
</body>
reader.readAsDataText (f, UTF-8); No funcion
reader.readAsDataURL (f); Muestra el archivo en Base64
¿Cómo puedo obtener un archivo de texto para que se muestre en la página?