Ajax XML

XML문서를 JSOn 형식으로 변환하는 플러그인
http://thomasfrank.se/xml_to_json.html

							window.onload = function () {
								var request = createRequest();

								request.onreadystatechange = function () {
									// 출력합니다.
									//alert(request.readyState);
									if (request.readyState == 4) {
										if (request.status == 200) {
											var xml = request.responseXML;

											// XML에서 각각의 요소를 뽑아옵니다.
											var people = xml.getElementsByTagName('person');
											var output = '';
											for (var i = 0; i < people.length; i++) {
												try {
													output += people[i].childNodes[1].childNodes[0].nodeValue + '\t';
													output += people[i].childNodes[3].childNodes[0].nodeValue + '\t';
													output += people[i].childNodes[5].childNodes[0].nodeValue + '\n';
												} catch (e) {
													output += people[i].childNodes[0].childNodes[0].nodeValue + '\t';
													output += people[i].childNodes[1].childNodes[0].nodeValue + '\t';
													output += people[i].childNodes[2].childNodes[0].nodeValue + '\t';
												}
											}
											alert(output);
										}
									}
								}

								request.open('GET', '/Home/MyFirstXMLAction', true);
								request.send();
							}
						
							 <script src="../../Scripts/xml2json.js"></script><!-- xml2json import -->
								// XMLHttpRequest 객체를 생성하는 함수
								function createRequest() {
									var request;
									try {
										request = new XMLHttpRequest();
									} catch (exception) {
									try {
										request = new ActiveXObject('Msxml2.XMLHTTP');
									} catch (innerException) {
											request = new ActiveXObject('Microsoft.XMLHTTP');
										}
									}
									return request;
								}


								window.onload = function () {
									var request = createRequest();

									request.onreadystatechange = function () {
										// 출력합니다.
										//alert(request.readyState);
										if (request.readyState == 4) {
											if (request.status == 200) {
												// XML을 JSOn으로 변경
												var json = xml2json.parser(request.responseText);

												for (var i in json['people']['person']) {
													var name = json['people']['person'][i].name;
													var gender = json['people']['person'][i].gender;
													var part = json['people']['person'][i].part;
												}
											}
										}
									}

									request.open('GET', '/Home/MyFirstXMLAction', true);
									request.send();
								}
						
							<people>
								<person>
									<name>윤인성</name>
									<gender>남자</gender>
									<part>기타</part>
								</person>
								<person>
									<name>연하진</name>
									<gender>여자</gender>
									<part>기타</part>
								</person>
							</people>
						
							{
								people:{
									person:[
										{
											name:'윤인성',
											gender:'남자',
											part:'기타'
										},
										{
											name:'연하진',
											gender:'여자',
											part:'기타'
										}
									]
								}
							}