1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | var nodeName = '' ; function makeXml(element, str) { $.each(element, function (key, sub){ if ( sub instanceof Object){ if ( sub instanceof Array ){ $.each(sub, function (idx, data){ str += makeXml(data, '<rows>' ); str += '</rows>' ; }); } else { nodeName = '<' +key+ '>' ; str += makeXml(sub, nodeName); str += '<!--' +key+ '-->' ; } } else { var value = sub; if (key == 'text' ){ str += (value== null )? '' :value; } } }); return str; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | var headerSet = {}; headerSet.staticsticKind = {text: '복합기후요소' }; headerSet.staticsticDate = {text: '년도별: 2010 ~ 2012년' }; headerSet.stn = {text: '강릉(105), 대관령(100), 동해(106), 북강릉(104), 속초(90), 영월(121), 원주(114), 인제(211), 정선군(217), 철원(95), 춘천(101), 태백(216), 홍천(212)' }; headerSet.staticsticEtcCondition = {text: '' }; headerSet.staticsticPrintColumn = {text: '평균기온,최고기온,최저기온' }; $.each(chartUploadFilePath, function (idx, path){ headerSet[staticsticChartPath+(idx+1)] = {text:path}; }); headerSet.lastTitleVal = {text: '복합요소 통계보고서' }; headerSet.firstColumn = {text: '지점번호' }; headerSet.secondColumn = {text: '요소' }; var resultData = {}; resultData.headerSet = headerSet; var source = {}; source.resultData = resultData; var xml = '<!--?xml version="1.0" encoding="UTF-8"?-->' ; var result = makeXml(source, xml); console.log(result); |
v
'웹 개발 > 스크립트 일반' 카테고리의 다른 글
숫자 뒤 % 붙이기. (1) | 2017.11.30 |
---|---|
숫자 외 몇몇 키 만 입력받기 (0) | 2017.11.30 |
String to Date (0) | 2017.11.29 |
자바스크립트 Array remove (0) | 2013.08.28 |