JAVA開発メモ
XPP3 のバックアップ差分(No.1)
 

[トップ|一覧|単語検索|最終更新|バックアップ|ヘルプ]






  


  -[[XML Pull Parsing Common API:http://www.xmlpull.org/]]
  

   import java.io.FileInputStream;
   import java.io.IOException;
   import java.io.StringReader;
  
   import org.xmlpull.v1.XmlPullParser;
   import org.xmlpull.v1.XmlPullParserException;
   import org.xmlpull.v1.XmlPullParserFactory;
  
   public class SimpleXmlPullApp {
  
       public static void main(String args[]) throws XmlPullParserException, IOException {

           XmlPullParserFactory factory = XmlPullParserFactory.newInstance();

           factory.setNamespaceAware(true);

           XmlPullParser xpp = factory.newPullParser();
  

           if (args != null && args.length > 0) {

               xpp.setInput(new FileInputStream(args[0]), "UTF-8");
           } else {

               xpp.setInput(new StringReader("<foo att='1'>Hello World!</foo>"));
           }
  
           int eventType = xpp.getEventType();

           while (eventType != XmlPullParser.END_DOCUMENT) {

               if (eventType == XmlPullParser.START_DOCUMENT) {
                   System.out.println("Start document");
               } else if (eventType == XmlPullParser.START_TAG) {

                   System.out.println("Start tag:" + xpp.getName());
                   for (int i = 0; i < xpp.getAttributeCount(); i++) {

                       System.out.print(" Attribute:" + xpp.getAttributeName(i));
                       System.out.print("=" + xpp.getAttributeValue(i));
                       System.out.println("(Tyep:" + xpp.getAttributeType(i) + ")");
                   }
               } 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();
           }
           System.out.println("End document");
       }
   }
  

   Start document
   Start tag:foo
    Attribute:att=1(Tyep:CDATA)
   Text:Hello World!
   End tag:foo
   End document
  

トップ 一覧 検索 最終更新 バックアップ   ヘルプ   最終更新のRSS

Modified by MT22(Moriwaki Takashi)

"PukiWiki" 1.3.7 Copyright © 2001,2002,2003 PukiWiki Developers Team. License is GNU/GPL.
Based on "PukiWiki" 1.3 by sng
Powered by PHP 7.4.33

HTML convert time to 0.002 sec.