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);  };

카테고리미분류

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다