XmlPullParserFactory XPPF = XmlPullParserFactory.newInstance();
  XPPF.setNamespaceAware(true);
  XmlPullParser XPP = XPPF.newPullParser();
  
  XPP.setInput(new StringReader ( "<foo>Hello World!</foo>"));  
  int nEventType = XPP.getEventType();
  
         while (nEventType != XmlPullParser.END_DOCUMENT)
         {
             if(nEventType == XmlPullParser.START_DOCUMENT)
             {
                 Log.d("XML_PARSING", "Start document");                  
             }
             else if(nEventType == XmlPullParser.START_TAG)
             {
              Log.d("XML_PARSING", "Start tag - "+XPP.getName());
             }
             else if(nEventType == XmlPullParser.END_TAG)
             {
              Log.d("XML_PARSING", "End tag - "+XPP.getName());
             }
             else if(nEventType == XmlPullParser.TEXT)
             {
              Log.d("XML_PARSING", "Text - "+XPP.getName());
             }
             nEventType = XPP.next(); 
      }
         System.out.println("End document");


 

처음엔 setInput 부분을 assets에서 가져온 XML로 읽어들였을때


capture_2011_09_13_14_08_39_1.png

 

Start document

Start tag - INFO

Text - null

Start tag - NUM

Text - null

End tag - NUM

Text - null

Start tag - NAME

Text - null

End tag - NAME

Text - null

Start tag - IMG_URL

Text - null

End tag - IMG_URL

Text - null

Start tag - EXPLAIN

Text - null

End tag - EXPLAIN

Text - null

End tag - INFO

Text - null

Start tag - INFO

Text - null

...

...


로그 찍으면 요런식으로 뜹니다.

그리고 위와 같이 (예제 : http://developer.android.com/reference/org/xmlpull/v1/XmlPullParser.html)

XPP.setInput(new StringReader ( "<foo>Hello World!</foo>"));

 문자열을 넣어줬을 때에도 로그가


Start document

Start tag - foo

Text - null

End tag - foo


요렇게 뜹니다.

인코딩 설정을 해주고

Stream을 Byte로 읽어와도 같은 현상이 일어나네요.



profile