지도 API를 사용호출시 브라우저에서 호출하면 정상인데

JAVA 소스에서 호출하면 다음과 같은 에러가 떴다.

(parameter : 서울특별시 강남구 강남대로)

[Fatal Error] :3:22: An invalid XML character (Unicode: 0x1c) was found in the CDATA section.


문제는 브라우저에서 호출할 때, UrlEncoding을 해서 보내는데

그것을 JAVA에서 Decoding을 하고 그대로 사용하니

결국 Encoding안된 parameter가 넘어가서 에러가 나는듯 하네


try{

String address = URLEncoder.encode(addr, "UTF-8");

String apiKey = "Naver 지도API";

String encoding = "utf-8";

String coord = "latlng";//latlng, tm128(navigation 용 : default)

String target = "http://openapi.map.naver.com/api/geocode.php";

String params = "?key=" + apiKey + "&encoding=" + encoding + "&coord=" + coord + "&query=" + address;

URL url = new URL(target+params);

URLConnection connection = url.openConnection();

try{

InputStream in = connection.getInputStream();

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

DocumentBuilder builder = factory.newDocumentBuilder();

Document doc = builder.parse(in);

NodeList itemNodes = doc.getElementsByTagName("item");

for(int i = 0; i < itemNodes.getLength(); i++){

Node item = itemNodes.item(i);


NodeList childNodes = item.getChildNodes();

//public static final short ELEMENT_NODE = 1;

//public static final short ATTRIBUTE_NODE = 2;

//public static final short TEXT_NODE = 3;

 

for( int j = 0 ; j < childNodes.getLength(); j++){

Element ele = null;

Node childNode = childNodes.item(j);

if (childNode.getNodeType() != Node.ELEMENT_NODE){

continue;

}

String eleTag = childNode.getNodeName();

if( "point".equals(eleTag)){

NodeList pointList = childNode.getChildNodes();

for(int m = 0; m < pointList.getLength(); m++){

Node aPoint = pointList.item(m);

String pointName = aPoint.getNodeName();

if("x".equals(pointName)){

//logger.debug(aPoint.getNodeName() + " : " + aPoint.getTextContent());

}else if("y".equals(pointName)){

//logger.debug(aPoint.getNodeName() + " : " + aPoint.getTextContent());

}

}

break;

}

if( "address".equals(eleTag)){

continue;

}

if( "addrdetail".equals(eleTag)){

continue;

}

}//end of for j

}//end of for i

}catch(Exception e){

e.printStackTrace();

}

}catch(Exception e){

e.printStackTrace();

    }


728x90
BLOG main image
"그게 뭐 어쨌다는 거냐?" 늘 누가 나에게 나에대한 말을할 때면 이말을 기억해라. by nobang

카테고리

nobang이야기 (1933)
Life With Gopro (7)
Life With Mini (79)
Diary (971)
너 그거 아니(do you know) (162)
난 그래 (159)
Study (290)
속지말자 (10)
Project (34)
Poem (15)
Song (0)
Photo (113)
낙서장 (45)
일정 (0)
C.A.P.i (2)
PodCast (0)
nobang (27)
고한친구들 (4)
recieve (0)
History (0)
android_app (2)

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

Total :
Today : Yesterday :