Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 26 | 27 | 28 | 29 | 30 |
Tags
- AWT
- Java
- 배열
- 오버로딩
- paint
- 어노테이션
- Eclips
- 이클립스
- 안드로이드
- 생성자
- 에러페이지
- mybatis
- JavaScript
- 예외처리
- Menu
- Spring
- Graphic
- 기본
- 국제화
- 전화걸기
- 메서드
- 클래스
- HTML
- JSP
- Android
- layout
- 메소드
- OGNL
- struts2
- oracle
Archives
- Today
- Total
note
xml Url 파싱 본문
String address =""; try { //116.91722222222222,27.305833333333332 //江西省抚州市黎川县 // DOM Document 객체를 생성하는 단계 DocumentBuilderFactory f = DocumentBuilderFactory.newInstance(); DocumentBuilder parser = f.newDocumentBuilder(); // XML 파일 파싱하는 단계 Document xmlDoc = null; String url ="http://map.dootms.com:8081/rgeocode/simple?key=c99d0ae1648e5610bd00c5126a4805132ee938ea5c8f5ac0b7ad23c110793ad1fcf4d3c8d41344d5&resType=xml&encode=utf-8&range=3000&roadnum=10&crossnum=3&poinum=10&retvalue=1&sid=7001®ion="+CommonUtil.nvl(longs)+","+CommonUtil.nvl(lat)+"&rid=434766"; //String url ="C:/Users/eric/Desktop/poilist.xml"; // error position 114.30194444444444,30.711944444444445 //118.48444444444445위도 : 38.07916666666667 //String url = "http://map.dootms.com:8081/rgeocode/simple?key=c99d0ae1648e5610bd00c5126a4805132ee938ea5c8f5ac0b7ad23c110793ad1fcf4d3c8d41344d5&resType=xml&encode=utf-8&range=3000&roadnum=10&crossnum=3&poinum=10&retvalue=1&sid=7001®ion=&rid=434766"; //String url = "http://map.dootms.com:8081/rgeocode/simple?key=c99d0ae1648e5610bd00c5126a4805132ee938ea5c8f5ac0b7ad23c110793ad1fcf4d3c8d41344d5&resType=xml&encode=utf-8&range=3000&roadnum=10&crossnum=3&poinum=10&retvalue=1&sid=7001®ion="+CommonUtil.nvl(longs)+","+CommonUtil.nvl(lat)+"&rid=434766"; xmlDoc = parser.parse(url); // parse는 결과값이라고 생각하자 // 루트 엘리먼트 접근 Element root = xmlDoc.getDocumentElement(); int length = root.getElementsByTagName("spatial").getLength(); for (int i = 0; i < length; i++) { Node vNode = root.getElementsByTagName("province").item(i); //성 Node province = ((Element) vNode).getElementsByTagName("name").item(0); vNode = root.getElementsByTagName("city").item(i); //시 Node city = ((Element) vNode).getElementsByTagName("name").item(0); vNode = root.getElementsByTagName("district").item(i); //구 Node district = ((Element) vNode).getElementsByTagName("name").item(0); //예외처리 if(!root.getElementsByTagName("roadlist").item(i).getTextContent().equals("")) vNode = root.getElementsByTagName("roadlist").item(i); else if (!root.getElementsByTagName("poilist").item(i).getTextContent().equals("")) vNode = root.getElementsByTagName("poilist").item(i); else if(!root.getElementsByTagName("crosslist").item(i).getTextContent().equals("")) vNode = root.getElementsByTagName("crosslist").item(i); //거리 //vNode = root.getElementsByTagName("roadlist").item(i); //거리2 //vNode = root.getElementsByTagName("poilist").item(i); //거리 3 //vNode = root.getElementsByTagName("crosslist").item(i); //예외처리 2 if(root.getElementsByTagName("crosslist").item(i).getTextContent().equals("") && root.getElementsByTagName("poilist").item(i).getTextContent().equals("") && root.getElementsByTagName("roadlist").item(i).getTextContent().equals("")){ address += province.getTextContent(); //성 address += city.getTextContent(); //시 address += district.getTextContent(); //구 }else{ //거리 이름 Node roadlist = ((Element) vNode).getElementsByTagName("name").item(0); //거리의 방위 Node direction = ((Element) vNode).getElementsByTagName("direction").item(0); String direction2 =direction.getTextContent(); direction2 = direction2.replace("East", "东"); direction2 = direction2.replace("West","西"); direction2 = direction2.replace("South","南"); direction2 = direction2.replace("North","北"); //그 길까지의 거리 Node distance = ((Element) vNode).getElementsByTagName("distance").item(0); address += province.getTextContent(); //성 address += city.getTextContent(); //시 address += district.getTextContent(); //구 address += CommonUtil.nvl(roadlist.getTextContent()); //거리 이름 address += CommonUtil.nvl(direction2); //거리 방위 address += CommonUtil.nvl(distance.getTextContent()); //떨어진 거리 } System.out.println("###### address :"+address); } } catch (Exception e) { System.out.println(e.getMessage()); System.out.println(e.toString()); }