반응형
XML 형식에서 원하는 노드의 값만 골라내고 싶을 때 사용하는 ASP 예제입니다.
아래는 xml 형태의 구글맵 지오코딩 결과입니다.
지오코딩한 결과 값에서
위도(Latitude)와 경도(Longitude)의 값만 추출히는 ASP 예제입니다.
<%
Set xmlHttp = Server.CreateObject("Microsoft.XMLHTTP")
'인코딩 관련 소스는 생략
request_url = "http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&address=서울시"
xmlHttp.Open "GET", request_url, false
xmlHttp.Send(null)
str_xml = xmlHttp.ResponseText
If str_xml <> "" Then
'XML 개체 인스턴스 생성
Set xmldoc = Server.CreateObject("Microsoft.XMLDOM")
xmldoc.async = false
xmldoc.validateOnParse = false
rtlValue = xmldoc.loadXML(str_xml)
Set responseYN = xmldoc.selectNodes("//GeocodeResponse")
Set selNode = xmldoc.selectNodes("//location")
'GeocodeResponse의 하위노드인 status의 값(지오코딩 결과값)이 OK 이면
If responseYN(0).childNodes(0).text = "OK" Then
'location 노드의 하위 값 중 첫번째에 위치한 값(위도)
response.write selNode(0).childNodes(0).text '상차지 위도
'location 노드의 하위 값 중 두번째에 위치한 값(위도)
response.write selNode(0).childNodes(1).text '상차지 경도
End If
Set responseYN = Nothing
Set selNode = Nothing
Set xmldoc = Nothing
End If
%>
반응형
'Language > ASP' 카테고리의 다른 글
| ASP 엑셀파일로 저장하기 (2) | 2013.09.26 |
|---|---|
| (ASP) HTML 태그 제거 (0) | 2013.04.05 |
| ASP 버퍼 사용(Response.flush, Buffer, Clear, End) (0) | 2013.02.04 |
| ASP get방식, post방식 예제(자바스크립트로 페이지 이동) (2) | 2013.01.31 |
| ASP 오라클 스토어드 프로시져(stored procedure) 사용 (0) | 2013.01.31 |
| ASP SQL Injection 방어 소스 (0) | 2013.01.24 |
| ASP 문자열 치환(Replace) (3) | 2013.01.24 |
| ASP 천단위 콤마(FormatNumber) (0) | 2013.01.24 |
| ASP 아작스,AJAX (XMLHTTP) (0) | 2013.01.22 |
| ASP 배열 사용 방법 (2) | 2013.01.22 |