- 浏览: 299101 次
- 性别:
- 来自: 上海
-
最新评论
-
再_见孙悟空:
写的不错
Dialog -
a549262189:
支持下,正好在学习这块的内容!
Android Gesture Detector -
dcsff:
受教了
LayoutInflater -
庆_啊:
真厉害。
LayoutInflater -
ghj234:
学习了,哈哈
LayoutInflater
1. KXmlParser
java.lang.Object
org.kxml2.io.KXmlParser
//定义一个事件采用回调的方式,直到读取xml完毕。 public int getEventType() throws org.xmlpull.v1.XmlPullParserException //遍历下一个事件,返回一个事件的类型 public int next() throws org.xmlpull.v1.XmlPullParserException, java.io.IOException //得到当前Tag名字 public String getName() //获取文本 public String getText() //得到当前Tag下面的属性数量 public int getAttributeCount() //得到当前Tag下面指定位置的属性名称 public String getAttributeName(int index) //得到当前Tag下面指定位置的属性植 public String getAttributeValue(int index) public String getAttributeValue(java.lang.String namespace, java.lang.String name)
(1)
XmlPullParser.START_DOCUMENT
= 0: Signalize that parser is at the very beginning of the document and nothing was read yet. This event type can only be observed by calling getEvent() before the first call to next(), nextToken, or nextTag()).
XmlPullParser.END_DOCUMENT
= 1: Logical end of the xml document. Returned from getEventType, next() and nextToken() when the end of the input document has been reached.
Note
: calling again next() or nextToken() will result in exception being thrown.
(2)
XmlPullParser.START_TAG
= 2: Returned from getEventType(), next(), nextToken() when a start tag was read. The name of start tag is available from getName(), its namespace and prefix are available from getNamespace() and getPrefix() if namespaces are enabled. See getAttribute* methods to retrieve element attributes. See getNamespace* methods to retrieve newly declared namespaces.
XmlPullParser.END_TAG
= 3: Returned from getEventType(), next(), or nextToken() when an end tag was read. The name of start tag is available from getName(), its namespace and prefix are available from getNamespace() and getPrefix().
XmlPullParser.TEXT
= 4: Character data was read and will is available by calling getText().
Note
: next() will accumulate multiple events into one TEXT event, skipping IGNORABLE_WHITESPACE, PROCESSING_INSTRUCTION and COMMENT events, In contrast, nextToken() will stop reading text when any other event is observed. Also, when the state was reached by calling next(), the text value will be normalized, whereas getText() will return unnormalized content in the case of nextToken(). This allows an exact roundtrip without chnanging line ends when examining low level events, whereas for high level applications the text is normalized apropriately.
2. 例子
public Object getBasicInfo(String url, ActionDispatcher dispatcher) { InputStream is = ActionConstants.getHttpPool().process(url, dispatcher); int count = 0, _count = -1; String temp = null; Vector tags = new Vector(); try { KXmlParser parser = new KXmlParser(); parser.setInput(new InputStreamReader(is)); parser.setInput(is, "UTF-8"); //纠正中文乱码 int eventType = parser.getEventType(); while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_TAG) { if ("result".equals(parser.getName())) { if (parser.getAttributeValue(0) != null) temp = parser.getAttributeValue(0); if (!"100".equals(temp)) NaviException.getConnException(temp); } else if ("hot_spot".equals(parser.getName())) { int size = parser.getAttributeCount(); for (int k = 0; k < size; k++) { if ("name".equals(parser.getAttributeName(k))) { if (parser.getAttributeValue(k) != null) temp = parser.getAttributeValue(k); if (temp == null || temp.trim().length() < 1) { } else { } } else if ("category_id".equals(parser.getAttributeName(k))) { } else if ("id".equals(parser.getAttributeName(k))) { } } } else if ("address".equals(parser.getName())) { count = 1; } else if ("phone_number".equals(parser.getName())) { count = 2; } else if ("introduction".equals(parser.getName())) { count = 3; } else if ("tag".equals(parser.getName())) { count = 4; _count++; } } else if (eventType == XmlPullParser.TEXT) { if (parser.getText() != null) temp = parser.getText(); switch (count) { case 1: count = 0; // 将count清零, 防止将脏数据再次赋值 if (temp != null && temp.trim().length() >= 1) { } break; case 2: count = 0; // 将count清零 if (temp != null && temp.trim().length() >= 1) { } break; case 3: count = 0; // 将count清零 if (temp != null && temp.trim().length() >= 1) { } break; case 4: count = 0; // 将count清零 if (temp != null && temp.trim().length() >= 1) { tags.insertElementAt(temp, _count); } break; } } eventType = parser.next(); } } catch (Exception e) { e.printStackTrace(); } finally { if (is != null) { try { is.close(); } catch (IOException e1) { e1.printStackTrace(); } is = null; } } return null; }
3. 资料下载
http://download.csdn.net/source/1686003
- most_simple_kxml_package.rar (20.6 KB)
- 下载次数: 31
发表评论
-
线程过多and高效MIDP编程
2010-05-03 17:42 0见附件 -
XML解析
2010-02-02 23:25 1285下面代码用到了jdom和dom4j两个包 public cl ... -
解压缩
2010-02-02 23:25 1158/* * 非面向对象语言要实现保存工作数据(如一个绘图程序 ... -
回车换行符
2010-01-21 13:52 136511 换行符:另起一行,'\n'10,仅仅把一个长行截断成两 ... -
Thread Pool
2010-01-14 15:27 978public class WorkQueue { p ... -
FileConnection
2010-01-12 15:39 15381. 引言 FileConnection API 是一 ... -
Customized Menu for JavaME
2009-10-10 11:36 1107参考文档: http://www.iteye.com/top ... -
自定义repeat()方法
2009-09-23 17:42 1367j2me的Canvas中有一个repeat()回调方法。大部分 ... -
J2ME移植-键值
2009-09-23 15:07 16621. J2ME标准api中Canvas中定义的键值有17(方向 ... -
Http线程阻塞分析
2009-08-23 16:48 4383先做一个总结:Http连接线程发生阻塞,会影响其他线程也出现阻 ... -
jar和jad解释
2009-08-20 23:22 1264整理电脑,从F盘挖坟挖出的股东,也贴出来吧 如果是K- ... -
图片在程序内存中的占有量
2009-08-20 17:58 27291. 图片占内存容量计算公式为: 图片所占内存大小 ... -
如何从网络中获取png图片
2009-08-03 19:54 20581. J2ME // 方法1 Connector conn ... -
cmnet和cmwap的访问
2009-07-30 11:06 2370CMWAP(通过WAP网关代理,由WAP网关连接服务器,然后将 ... -
JSR75 FileConnection Optional Package 使用方法
2009-07-29 17:09 1641package forrest.fcop; imp ... -
mobile日志
2009-07-29 16:05 9971.项目中的实际应用 这个demo用到了JSR75 - ... -
DoubleBuffer 实现
2009-07-29 10:22 1300绘制地图的时候会出现图片断裂,屏幕闪烁等绘图效率问题 ... -
System.getProperty(String key)和MIDlet.getAppProperty(String key)
2009-07-13 17:53 20071. System.getProperty(String ... -
WTK的安全特性
2009-07-01 17:28 10901. MIDlet套件签名的背景 ... -
纳米星开发遇到的一些bug
2009-06-30 17:01 10661.Stream和Connection使用后要关闭 ...
相关推荐
chm格式的kxml doc,用quickchm做的,不过索引没做,因为kxml的类少。
这个压缩包“kxml2_doc_src”包含了KXML2的完整帮助文档和源代码,为开发者提供了详尽的学习和参考资源。 一、KXML2概述 KXML2是由Kevin Conner开发的,它是一个基于事件驱动的XML解析器,专为J2ME和Android平台...
* PULL:经常用在 J2ME 对于节点解决比较好,类似 SAX 方式,同样很节省内存,在 J2ME 中我们经常使用的 KXML 库来解析 五、ListView 的优化方案 * 假如自定义适配器,那么在 getView 方法中要考虑方法传进来的...
- **KXML**:KXML是一个增量解析器,它逐段解析XML文档,适合处理较大的数据集。这种方式能够有效地管理内存,尤其适用于资源受限的环境。 - **NanoXML**:NanoXML采用一步解析方式,即一次性加载整个文档到内存中并...
NSArray *items = [doc nodesForXPath:kXML error:nil]; for (DDXMLElement *obj in items) { xmlData *data = [[xmlData alloc] init]; DDXMLElement *aUser = [obj elementForName:KUSER]; if(aUser) ...
- `org.kxml2.io.KXmlParser`:Android系统默认使用的XML Pull解析器实现,基于kXML库。 - 源码中,关注`parse()`方法,它是解析过程的入口,`next()`和`eventType`属性用于跟踪解析进度。 4. 使用PPT进行学习: ...
Java中,`org.xmlpull.v1.XmlPullParser`接口及其实现如KXML2库提供了拉式解析的功能。以下是一个简单的拉式解析示例: ```java import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserFactory...