안드로이드 개발 질문/답변
(글 수 45,052)
XmlPullParser로 웹의 xml주소를 넣어 파싱을 하려고 하는데요 파서가 제대로된 주소를 못가져오는지
로그캣으로 확인을 해보면 이상한 html파일을 파싱하는것 같아요.
파싱을 하려고 하는 주소는 http://youtubeowaraitv.blog32.fc2.com/?xml 이구요.
코드는 다음과 같이 해서 DDMS로 확인하였습니다.
try {
URL text = new URL("http://youtubeowaraitv.blog32.fc2.com/" + "?xml");
System.out.println(text.toString());
XmlPullParserFactory parserCreator = XmlPullParserFactory.newInstance();
XmlPullParser xpp = parserCreator.newPullParser();
xpp.setInput(text.openStream(), null);
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if(eventType == XmlPullParser.START_DOCUMENT) {
System.out.println("Start document");
} else if(eventType == XmlPullParser.END_DOCUMENT) {
System.out.println("End document");
} else if(eventType == XmlPullParser.START_TAG) {
System.out.println("Start tag "+xpp.getName());
} else if(eventType == XmlPullParser.END_TAG) {
System.out.println("End tag "+xpp.getName());
} else if(eventType == XmlPullParser.TEXT) {
System.out.println("Text "+xpp.getText());
}
eventType = xpp.next();
}결과는 다음과 같았습니다.
01-31 12:56:33.285: INFO/System.out(254): Start document
01-31 12:56:33.294: INFO/System.out(254): Start tag html
01-31 12:56:33.294: INFO/System.out(254): Text
01-31 12:56:33.294: INFO/System.out(254): Start tag head
01-31 12:56:33.294: INFO/System.out(254): Text
01-31 12:56:33.294: INFO/System.out(254):
01-31 12:56:33.305: INFO/System.out(254): Start tag meta
01-31 12:56:33.305: INFO/System.out(254): End tag meta
01-31 12:56:33.305: INFO/System.out(254): Text
01-31 12:56:33.315: INFO/System.out(254):
01-31 12:56:33.315: INFO/System.out(254): Start tag meta
01-31 12:56:33.315: INFO/System.out(254): End tag meta
01-31 12:56:33.315: INFO/System.out(254): Text
01-31 12:56:33.315: INFO/System.out(254):
01-31 12:56:33.315: INFO/System.out(254): Start tag title
01-31 12:56:33.315: INFO/System.out(254): Text - Youtube�o���G�e�B����q��
01-31 12:56:33.315: INFO/System.out(254): End tag title
01-31 12:56:33.325: INFO/System.out(254): Text
01-31 12:56:33.325: INFO/System.out(254):
01-31 12:56:33.325: INFO/System.out(254): Start tag link
01-31 12:56:33.325: INFO/System.out(254): End tag link
01-31 12:56:33.325: INFO/System.out(254): Text
01-31 12:56:33.335: INFO/System.out(254):
01-31 12:56:33.335: INFO/System.out(254): Start tag link
01-31 12:56:33.335: INFO/System.out(254): End tag link
01-31 12:56:33.335: INFO/System.out(254): Text
01-31 12:56:33.335: INFO/System.out(254):
01-31 12:56:33.335: INFO/System.out(254): Start tag link
01-31 12:56:33.335: INFO/System.out(254): End tag link
01-31 12:56:33.335: INFO/System.out(254): Text
01-31 12:56:33.345: INFO/System.out(254):
01-31 12:56:33.345: INFO/System.out(254): Start tag script
01-31 12:56:33.345: INFO/System.out(254): End tag script
01-31 12:56:33.345: INFO/System.out(254): Text
01-31 12:56:33.345: INFO/System.out(254):
01-31 12:56:33.345: INFO/System.out(254): Start tag script
01-31 12:56:33.345: INFO/System.out(254): End tag script
01-31 12:56:33.345: INFO/System.out(254): Text
01-31 12:56:33.345: INFO/System.out(254):
01-31 12:56:33.355: INFO/System.out(254): Start tag script
01-31 12:56:33.355: INFO/System.out(254): Text
01-31 12:56:33.355: INFO/System.out(254): window.onresize = function(){
01-31 12:56:33.355: INFO/System.out(254): setOrientation();
01-31 12:56:33.355: INFO/System.out(254): }
01-31 12:56:33.355: INFO/System.out(254): window.onload = function() {
01-31 12:56:33.355: INFO/System.out(254): setTimeout(function(){window.scrollTo(0, 1);}, 100);
01-31 12:56:33.355: INFO/System.out(254): setTimeout(function(){setOrientation();},300);
01-31 12:56:33.365: INFO/System.out(254): }
01-31 12:56:33.365: INFO/System.out(254): function submit(){
01-31 12:56:33.365: INFO/System.out(254): document.form1.submit();
01-31 12:56:33.365: INFO/System.out(254): }
01-31 12:56:33.365: INFO/System.out(254):
01-31 12:56:33.365: INFO/System.out(254): End tag script
01-31 12:56:33.365: INFO/System.out(254): Text
01-31 12:56:33.365: INFO/System.out(254): End tag head
01-31 12:56:33.365: INFO/System.out(254): Text
01-31 12:56:33.375: INFO/System.out(254): Start tag body
01-31 12:56:33.375: INFO/System.out(254): Text
01-31 12:56:33.375: INFO/System.out(254):
01-31 12:56:33.375: INFO/System.out(254): Start tag div
01-31 12:56:33.375: INFO/System.out(254): Text
01-31 12:56:33.375: INFO/System.out(254):
01-31 12:56:33.385: INFO/System.out(254): Start tag div
01-31 12:56:33.385: INFO/System.out(254): Text
01-31 12:56:33.395: INFO/System.out(254):
01-31 12:56:33.395: INFO/System.out(254): Start tag h1
01-31 12:56:33.395: INFO/System.out(254): Text Youtube�o���G�e�B����q��
01-31 12:56:33.405: INFO/System.out(254): End tag h1
01-31 12:56:33.405: INFO/System.out(254): Text
01-31 12:56:33.405: INFO/System.out(254):
01-31 12:56:33.405: INFO/System.out(254):
분명 xml의 주소를 넣었는데 html태그들이 튀어나오는건 왜그런것일까요?




웹브라우저의 소스보기로 하면 XML 태그가 나오지만..
파이어폭스의 파이어버그에서 HTML 탭으로 들어가면 소스가 HTML 형태로 나옵니다..
IE 8 버전이시면 도구->개발자 도구로 가셔서 스타일 탭 들어가보시면..
html 태그 문법으로 나오시는게 보일껍니다..