2
저는 AngularJS를 사용하여 사용자가 업로드 한 파일을 가지고 있으며 XML을 사용하여 파일 내용을 조작하고 싶습니다. 그러나 DOMParser에서 텍스트 파일을 인식하는 데 어려움이 있습니다. index.html을AngularJS에서 FileReader 및 DOMParser 사용
<div ng-controller = "myCtrl">
<input type="file" file-model="myFile"/>
<button ng-click="uploadFile()">upload me</button>
</div>
는 txtFile 올바르게 Reader.onLoad 내 콘솔에 프린트되고,이 예에서는
myApp.controller('myCtrl', ['$scope', 'fileUpload', function($scope, fileUpload){
$scope.uploadFile = function(){
var file = $scope.myFile;
reader = new FileReader();
reader.onload = function() {
showout.value = this.result;
txtFile = showout.value;
console.log(txtFile);
};
reader.readAsText(file);
parser=new DOMParser();
xmldoc = parser.parseFromString(txtFile,"text/xml");
console.log(xmlDoc);
을 app.js. 그러나 xmlDoc은 정의되지 않은 것으로 표시됩니다.
내가 DOMParser에서 읽을 수 있도록 파일을 참조하고 변환해야합니까?
참고 : ... xmldoc = parser.parseFromString ("bob", "text/xml")의 txtFile을 바꾸면 코드가 작동합니다.
미리 감사드립니다.