html5 download attribute를 활용한 file download ( ie, edge 포함)

html
<!DOCTYPE html>
<html>
<body>
  <a href="data:text/plain;charset=utf-8,'aaaaaaa'" download="aa.txt" id="aFi-file-download"></a>
  <script>
    function file_download(str, filename){
      var file = new Blob([str],{type: "text/plain;charset=utf-8"});
      if(window.navigator.msSaveOrOpenBlob) {
        window.navigator.msSaveOrOpenBlob(file, filename);
      } else {
        document.getElementById("aFi-file-download").href= "data:text/plain;charset=utf-8," + str;
        document.getElementById("aFi-file-download").download = filename;
        document.getElementById("aFi-file-download").click();
      }
    }
  </script>
</body>
</html>
call
file_download("abc", "wiz.txt");

xml to file

html
<!DOCTYPE html>
<html>
<body>
<a href="data:text/plain;charset=utf-8,'aaaaaaa'" id="aFi-file-download"></a>
<script>
function file_download(xmlstr, filename) {
  document.getElementById("aFi-file-download").href = "data:text/plain;charset=utf-8," + xmlstr;
  document.getElementById("aFi-file-download").download = filename;
  document.getElementById("aFi-file-download").click();
};
</script>

</body>
</html>
call
this.Button00_onclick = function(obj:nexacro.Button,e:nexacro.ClickEventInfo)
this.Button00_onclick = function(obj:nexacro.Button,e:nexacro.ClickEventInfo){ 
  var xml = '<?xml version="1.0" encoding="UTF-8"?><Sap><resultOtherCode>Y</resultOtherCode><tprtvrtlchtList><tprtvrtlchtVO><sn>BD00120190000004</sn><cmpnyCd>LENC</cmpnyCd><prufDe>20190131</prufDe><chitTyCd>DB</chitTyCd><pstngDe>20190131</pstngDe><crncyCd>KRW</crncyCd><vrtlchtNo>BD00120190000004</vrtlchtNo><hderTextCn>gwweb1/10081/정보시스템팀</hderTextCn><inputerEmpno>20090204</inputerEmpno><inputerDeptCd>10081</inputerDeptCd><moinSanctnNo>PD20094FE0D554016B93FBB89ACAD6C17</moinSanctnNo><accnutYear>2019</accnutYear><chitNo>5090000003</chitNo><chitCreatAt>Y</chitCreatAt><chitCreatResultCn>5090000003 전표가 LENC 회사 코드에 전기되었습니다.</chitCreatResultCn></tprtvrtlchtVO></tprtvrtlchtList></Sap>';
  file_download(xml, "aa.xml");
};

xml to json

this.gfn_FiXmlToJson = function( pXmlStr ) {
try {
var obj = {};
if (pXmlStr.children.length > 0) {
for (var i = 0; i < pXmlStr.children.length; i++) {
var item = pXmlStr.children.item(i);
var nodeName = item.nodeName;
if (typeof (obj[nodeName]) == “undefined”) {
obj[nodeName] = this.gfn_FiXmlToJson(item);
} else {
if (typeof (obj[nodeName].push) == “undefined”) {
var old = obj[nodeName];
obj[nodeName] = [];
obj[nodeName].push(old);
}
obj[nodeName].push(this.gfn_FiXmlToJson(item));
}
}
} else {
obj = pXmlStr.textContent;
}
return obj;
} catch (e) {
trace(e.message);
}
};

호출할때,

this.div_Detail_ful_uploadXml_onitemchanged = function(obj:nexacro.FileUpload,e:nexacro.FileUploadItemChangeEventInfo){
var oReader = new FileReader();
var oThis = this;
oReader.onload = function(e) {
var oParser = new DOMParser();
var oXmlDoc = oParser.parseFromString(oReader.result, “text/xml”);
if (oXmlDoc.documentElement){
this._xml = oXmlDoc.documentElement;
var oJson = oThis.gfn_FiXmlToJson(oXmlDoc.documentElement);
var sElctrnTaxBillNo = oJson.TaxInvoiceDocument.IssueID; //전자세금계산서번호
var sVndcstNm = oJson.TaxInvoiceTradeSettlement.InvoicerParty.NameText; //거래처명
var sVndcstNo = oJson.TaxInvoiceTradeSettlement.InvoicerParty.ID; //거래처번호
var sSplpc = oJson.TaxInvoiceTradeSettlement.SpecifiedMonetarySummation.ChargeTotalAmount; //공급가액
var sVat = oJson.TaxInvoiceTradeSettlement.SpecifiedMonetarySummation.TaxTotalAmount; //부가세액
var sPymntTotamt = oJson.TaxInvoiceTradeSettlement.SpecifiedMonetarySummation.GrandTotalAmount; //지불총액
….
}
};
oReader.readAsText(obj.filelist[0]._ref_file);  };