프로그래밍/ASP
asp 커리어넷 오픈api 학교주소검색 xml가져오기
p-a-r-k
2017. 3. 20. 16:26
반응형
'api key
strKey = "your api key"
sGetGubun = Request("gubun") '초중고구분
sGetkeyword = Request("keyword") '검색어
rows = 0
If sGetGubun = "1" Then
sGetGubun = "midd_list" '중학교
Else
sGetGubun = "high_list" '고등학교
End If
if not IsNULL(sGetGubun) and len(sGetGubun) Then
cngSearch = server.URLEncode(sGetkeyword)
'주소 정보 가져오기
sPath = "http://www.career.go.kr/cnet/openapi/getOpenApi?apiKey="& strKey &""_
& "&svcType=api&svcCode=SCHOOL&perPage=100&contentType=xml&gubun="& sGetGubun &"&searchSchulNm="& cngSearch
Set oDOM = Server.CreateObject("Microsoft.XMLDOM")
with oDOM
.async = False ' 동기식 호출
.setProperty "ServerHTTPRequest", True ' HTTP로 XML 데이터 가져옴
.Load(sPath)
end with
Set ResultNodes = oDOM.selectNodes("//dataSearch")
if ResultNodes.Length > 0 Then
Set Nodes = oDOM.selectNodes("//content")
rows = Nodes.Length
Else
rows = 0
End If
Set ResultNodes = Nothing
sXmlText = ""
sXmlText = sXmlText & ""
If rows > 0 Then
sXmlText = sXmlText & ""
sXmlText = sXmlText & "" & rows & " "
For each SubNodes in Nodes
nSeq = SubNodes.getElementsByTagName("seq")(0).Text'고유번호
sRegion = SubNodes.getElementsByTagName("region")(0).Text'지역
sSchoolName = SubNodes.getElementsByTagName("schoolName")(0).Text'학교명
sAdres = SubNodes.getElementsByTagName("adres")(0).Text'주소
sXmlText = sXmlText & "- "
sXmlText = sXmlText & "
"
sXmlText = sXmlText & " "
sXmlText = sXmlText & " "
sXmlText = sXmlText & " "
sXmlText = sXmlText & " "
Next
sXmlText = sXmlText & " "
Else
sXmlText = sXmlText & ""
sXmlText = sXmlText & "" & rows & " "
sXmlText = sXmlText & " "
End If
Response.ContentType = "text/xml"
REsponse.WRite sXmlText
Response.End
End If
반응형