안규 공부방

ACTIVE SERVER PAGE > Server.CreateObject("Microsoft.XMLDOM") - 외부 xml 불러오기 예제

등록일 : 2017-07-04 16:46 조회수 : 93,912

	Class XMLDOMClass
		   Private m_DOM ' XMLDOM 객체

		   ' ---------------------- 생성자 -----------------------
		   Private Sub Class_Initialize()
			  Set m_DOM = Server.CreateObject("Microsoft.XMLDOM")
		   End Sub
		 
		   ' ---------------------- 소멸자 -----------------------
		   Private Sub Class_Terminate()
			  Set m_DOM = Nothing
		   End Sub	 

		   ' ------------------- Property Get --------------------
		   Public Property Get TagText(tagName, index)
			  Dim Nodes
		 
			  Set Nodes = m_DOM.getElementsByTagName(tagName)
			  TagText = Nodes(index).Text
			  Set Nodes = Nothing
		   End Property
		 
		   Public Property Get Nodes(tagName)
			  Set Nodes = m_DOM.getElementsByTagName(tagName)
		   End Property
		 
		   ' ------------------- 원격 XML 읽기 --------------------
		   Public Function LoadHTTP(url)
			  with m_DOM
				 .async = False ' 동기식 호출
				 .setProperty "ServerHTTPRequest", True ' HTTP로 XML 데이터 가져옴
		   
				 LoadHTTP = .Load(url)
			  end with  
		   End Function
		 
		   ' ------------------- XML 파일 읽기 --------------------
		   Public Function Load(file)
			  with m_DOM
				 .async = False ' 동기식 호출
		   
				 Load = .Load( Server.MapPath(file) )
			  end with
		   End Function
		End Class

		
		'소스 시작
		
		dim oDOM, url


		' XML 데이터 주소
		url = "http://jeonjumart.co.kr/test.asp"

		 

		Set oDOM = new XMLDOMClass

		 

		with oDOM
		   if .LoadHTTP(url) Then
			For i=0 To 1
			  Response.Write "start:" & .TagText("start",i) & "
"
			  Response.Write "step:" & .TagText("step", i) & "
"
			Next
		   else
			  Response.Write "XML을 읽어오는데 실패하였습니다."
		   End if
		end with

		 

		Set oDOM = Nothing	



		'---------------------------------------------
		test.asp 파일내용

	
	 
	   
		yes
		4
		4,1,2,3
		9
	   
	   
		yes
		한글테스트
		5,1,2,3
		9
	   
	  
※ 혹시 도움이 되셨다면 댓글에 한마디 남겨주세요!
작성자   비밀번호
자동글 방지     (자동글 방지 기능입니다.)
내용   댓글달기 
이메일 문의 : cak0280@nate.com  
Copyright 2000 By ENTERSOFT.KR All Rights Reserved.