Letting User Open An Xml File On Client And Parse It Using Javascript
I'm trying to let a users on my site to save and XML file one the local machine and then later to load them using the HTML file element. Saving the file what done with iFrame. When
Solution 1:
I think you're looking for FileReader, new in HTML5. For IE < 10 you'll need to use the ActiveX FileSystemObject.
This code works for me on Chrome.
<scripttype="text/javascript">functiondoit(e) {
var files = e.target.files;
var reader = newFileReader();
reader.onload = function() {
var parsed = newDOMParser().parseFromString(this.result, "text/xml");
console.log(parsed);
};
reader.readAsText(files[0]);
}
document.getElementById("selectfile").addEventListener("change", doit, false);
</script><inputtype="file"id="selectfile" />
Post a Comment for "Letting User Open An Xml File On Client And Parse It Using Javascript"