JAVA開発メモ
XPP3
 

[リロード]   [新規|編集|差分|添付]   [トップ|一覧|単語検索|最終更新|バックアップ|ヘルプ]

サイトメニュー

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
Last-modified: Tue, 15 Feb 2005 14:08:10 UTC (6303d)
Link: FrontPage(2522d)

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.28

HTML convert time to 0.022 sec.