//XmlParser 20150715 추가
private void PullParserFromXML(String data){
boolean boolean_distance = false, boolean_itemList = false,
//PathList
boolean_pathList = false,
boolean_fId = false,
boolean_fName = false,
boolean_fX = false,
boolean_fY = false,
boolean_railLinkList = false,
boolean_railLinkId = false,
boolean_routeNm = false,
boolean_tId = false,
boolean_tName = false,
boolean_tX = false,
boolean_tY = false,
//pathList end. 배열로 해줘야할듯
boolean_time = false;
//itemList 끝
boolean done = false;
try {
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
XmlPullParser parser = factory.newPullParser();
parser.setInput(new StringReader(data));
String sTag;
int eventType = parser.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT){
switch(eventType){
case XmlPullParser.START_DOCUMENT :
subwayList = new ArrayList<SubwayData>(); break;
case XmlPullParser.END_DOCUMENT : break;
case XmlPullParser.START_TAG :
sTag = parser.getName();
if (sTag.equals("msgBody"));
if (sTag.equals("itemList")){
subwayData = new SubwayData(); // 객체 생성
boolean_itemList = true;
}
if (sTag.equals("distance"))
boolean_distance = true;
if (sTag.equals("pathList"))
subwayPathList = new ArrayList<SubwayPathList>(); //뭉텅이
// subwayPath = new SubwayPathList();
if (sTag.equals("fid"))
boolean_fId = true;
else if (sTag.equals("fname"))
boolean_fName = true;
else if (sTag.equals("fx"))
boolean_fX = true;
else if (sTag.equals("fy"))
boolean_fY = true;
/**
* 일단 rail 부분은 파싱하지 말고 나머지가 정상적으로 되나 테스트를 하자.
else if (sTag.equals("railLinkList")){
railLinkList = new RailLinkList();
while (sTag.equals("railLinkId")){
boolean_railLinkId = true;
} boolean_railLinkList = true;
}
*/
else if (sTag.equals("routeNm"))
boolean_routeNm = true;
else if (sTag.equals("tid"))
boolean_tId = true;
else if (sTag.equals("tname"))
boolean_tName = true;
else if (sTag.equals("tX"))
boolean_tX = true;
else if (sTag.equals("tY"))
boolean_tY = true;
if (sTag.equals("time"))
boolean_time = true;
break; //XmlPullParser.START_TAG case close
case XmlPullParser.END_TAG :
sTag = parser.getName();
if (sTag.equalsIgnoreCase("itemList") && subwayData != null)
if (sTag.equalsIgnoreCase("pathList") && subwayPathList != null)
subwayPathList.add(subwayPath);
subwayList.add(subwayData);
break;
case XmlPullParser.TEXT :
if (boolean_distance){
subwayData.setDistance(parser.getText());
boolean_distance = false;
} else if (boolean_pathList){
//? 추가해야할 것? 맨 마지막에 false 하자
if (boolean_fId){
// subwayData.setPathList(); how to ㅠㅠ
subwayPath.setfId(parser.getText());
boolean_fId = true;
} else if (boolean_fName){
subwayPath.setfName(parser.getText());
boolean_fName = true;
} else if (boolean_fX){
subwayPath.setfX(parser.getText());
boolean_fX = true;
} else if (boolean_fY){
subwayPath.setfY(parser.getText());
boolean_fY = true;
} // railLinkList 추가해야해
else if (boolean_routeNm){
subwayPath.setRouteNm(parser.getText());
boolean_routeNm = true;
} else if (boolean_tId){
subwayPath.setTid(parser.getText());
boolean_tId = true;
} else if (boolean_tName){
subwayPath.settName(parser.getText());
boolean_tName = true;
} else if (boolean_tX){
subwayPath.settX(parser.getText());
boolean_tX = true;
} else if (boolean_tY){
subwayPath.settY(parser.getText());
boolean_tY = true;
}
// subwayData.setPathList ?? 세팅하는게 필요할듯한데..
boolean_pathList = false;
} else if (boolean_time){
subwayData.setTime(parser.getText());
boolean_time = false; break;
}
eventType = parser.next();
}//switch close
Log.i("xmlParser", subwayData.getDistance() + "" + subwayData.getPathList());
TextView data1 = (TextView)findViewById(R.id.data1);
TextView data2 = (TextView)findViewById(R.id.data2);
TextView data3 = (TextView)findViewById(R.id.data3);
data1.setText(subwayPath.getfName());
data2.setText(subwayData.getDistance());
data3.setText(subwayData.getPathList().get(0).gettName());
}
} catch(Exception ex) {
}
}