xml 범용 파싱


@SuppressWarnings("unchecked")

private void getStoreInfo() throws SAXException, Exception {

Properties prop = PropertiesFactory.getProperties(PropertiesPath.ENV.build());

URL url = null;

URLConnection con = null;

for(Map<String, String> paramMap : getPlantList()) {

try {

System.out.println(prop.getProperty("vms.url") + "&plant=" + paramMap.get("PLANT"));

// vms.url=http://xxx.xxx.xxx.xxx:8080/enovia/mobileService/mService.jsp?action=siteInfo

url = new URL(prop.getProperty("vms.url") + "&plant=" + paramMap.get("PLANT"));

con = url.openConnection();

con.connect();

XMLMap xmlMap = new XMLMap(con.getInputStream());

Map<String, Object> resultMap = xmlMap.getMap();

if("200".equals(resultMap.get("code"))) {

// List<Map<String, String>> paramList = (List<Map<String, String>>) resultMap.get("furs");

insertStoreInfo((List<Map<String, String>>) resultMap.get("furs")); // TODO 1개일때는 오류났으나 수정

} else {

System.out.println("CODE    : " + resultMap.get("code"));

System.out.println("MESSAGE : " + resultMap.get("msg"));

continue;

}

} catch (IOException e) {

continue;

} catch (SQLException e) {

continue;

}

}

}

@SuppressWarnings("unchecked")

private void xmlStoreInfo() throws SAXException, Exception {

XMLMap xmlMap = new XMLMap(new File("/fashionscm/mobile/furList.xml"));

Map<String, Object> resultMap = xmlMap.getMap();

List<Map<String, String>> paramList = (List<Map<String, String>>) resultMap.get("furs");

insertStoreInfo(paramList);

// for(Map<String, String> storeMap : storeList) {

// System.out.println(storeMap);

// }

}


또다른 사용 예) 안드로이드에서..


@Override

public void update(ResponseEvent response) {

mMyLoadingDialog.dismiss();

String resultText = response.getResultData();

// WriteTextFile("FurInfo.txt", resultText);

try {

InputStream inputstream = new ByteArrayInputStream(resultText.getBytes("UTF-8"));


// 첫번째 방법

// XmlPullFeedParser parser = new XmlPullFeedParser(inputstream);

// List<VMSSiteInfo> messages = parser.parse();

//

// for (VMSSiteInfo vmsSiteInfo : messages) {

// System.out.println(vmsSiteInfo.getPlant()+" "+vmsSiteInfo.getFloor()+" "+

// vmsSiteInfo.getFurCode()+" "+vmsSiteInfo.getFurNo()+" "+vmsSiteInfo.getFurType());

// }

첫번째 방법 링크 : http://androi.tistory.com/204


// 두번째 방법

XMLMap xmlMap = new XMLMap(inputstream);

try {

Map<String, Object> resultMap = xmlMap.getMap();


if ("200".equals(resultMap.get("code"))) {

System.out.println("MESSAGE : " + resultMap.get("msg"));

zoneList = (List<Map<String, String>>) resultMap.get("lists");

for (Map<String, String> map : zoneList) {

System.out.println(map.get("plant") + " " + map.get("floor") + " " + map.get("zone") + " " + map.get("zoneTitle") + " "

+ map.get("zoneX") + " " + map.get("zoneZ") + " " + map.get("zoneSales"));

}

if (zoneList.size() > 0) {

addViews(zoneList.size());

}


} else {

System.out.println("CODE    : " + resultMap.get("code"));

System.out.println("MESSAGE : " + resultMap.get("msg"));

}

} catch (SAXException e) {

e.printStackTrace();

} catch (Exception e) {

e.printStackTrace();

}


} catch (UnsupportedEncodingException e) {

e.printStackTrace();

}


}


첨부파일


xml.zip


+ Recent posts