- 浏览: 189708 次
- 性别:
- 来自: 郑州
最新评论
-
gaoyansansheng:
,第一个方法是全角符转半角符吧?
Android TextView自动换行文字排版参差不齐的原因 -
wyyl1:
牛逼!用第一个方法就行了,简单!
Android TextView自动换行文字排版参差不齐的原因 -
XuNiu:
好内容虽然过了这么久了,但是一定要赞一下
android 命名规范
在Android中,如果要想完成PULL解析处理需要
org.xmlpull.v1.XmlPullParserFactory类org.xmlpull.v1.XmlPullParser接口的支持,XmlpullParserFatory工厂类的主要功能是可以通过里面提供的newPullParser()方法取得一个XmlPullParser接口的对象
公共接口
XmlPullParser
org.xmlpull.v1.XmlPullParser |
已知的间接子类
|
类概述
XML拉解析器是一个接口,定义分析功能提供的XMLPULL V1的API
有以下不同的解析器,根据功能设置的不同分别为:
- non-validating 解析器在XML 1.0规范定义当FEATURE_PROCESS_DOCDECL被设置为true
- validating parser XML 1.0规范中定义FEATURE_VALIDATION是true时 (and t这意味着,FEATURE_PROCESS_DOCDECL是true)
- when FEATURE_PROCESS_DOCDECL is false (这是默认的,如果需要不同的值,必须在解析之前开始改变) 然后解析器的根据XML 1.0 符合 non-validating 解析器的条件下,没有DOCDECL存在于XML文档中(内部实体仍然可以定义 这种运作模式的目的是在受限的环境中运作,如J2ME的。
有两个关键方法:next()和nextToken()。尽管next()提供了获得高水平的解析事件,nextToken()可以访问到较低层次的标识
当前的事件状态的解析器可以确定通过调用getEventType()方法。最初,解析器在START_DOCUMENT状态。
next()方法推动解析器到下一个事件。int的返回值下决定当前解析器的状态,完全相同的返回值以下调用getEventType()。
以下事件类型被next()
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(); xpp.setInput( new StringReader ( "<foo>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()); } 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 Text Hello World! End tag foo End document
API用法的更多细节,请参阅http://www.xmlpull.org
Summary(概要)
int | CDSECT | A CDATA sections was just read; this token is available only from calls to nextToken(). |
int | COMMENT | XML注释 |
int | DOCDECL | An XML document type declaration was just read. |
int | END_DOCUMENT | Logical end of the xml document. |
int | END_TAG | Returned from getEventType(), next(), or nextToken() when an end tag was read. |
int | ENTITY_REF | An entity reference was just read; this token is available from nextToken() only. |
String | FEATURE_PROCESS_DOCDECL | This feature determines whether the document declaration is processed. |
String | FEATURE_PROCESS_NAMESPACES | This feature determines whether the parser processes namespaces. |
String | FEATURE_REPORT_NAMESPACE_ATTRIBUTES | This feature determines whether namespace attributes are exposed via the attribute access methods. |
String | FEATURE_VALIDATION | If this feature is activated, all validation errors as defined in the XML 1.0 specification are reported. |
int | IGNORABLE_WHITESPACE | Ignorable whitespace was just read. |
String | NO_NAMESPACE | This constant represents the default namespace (empty string "") |
int | PROCESSING_INSTRUCTION | An XML processing instruction declaration was just read. |
int | START_DOCUMENT | 解析器在文档的开头,处于即将阅读状态 |
int | START_TAG | Returned from getEventType(), next(), nextToken() when a start tag was read. |
int | TEXT | Character data was read and will is available by calling getText(). |
public static final String[] | TYPES | This array can be used to convert the event type integer constants such as START_TAG or TEXT to to a string. |
abstract void |
defineEntityReplacementText(String entityName, String replacementText)
Set new value for entity replacement text as defined in XML 1.0 Section 4.5 Construction of Internal Entity Replacement Text.
|
abstract int |
getAttributeCount()
Returns the number of attributes of the current start tag, or -1 if the current event type is not START_TAG
|
abstract String |
getAttributeName(int index)
Returns the local name of the specified attribute if namespaces are enabled or just attribute name if namespaces are disabled.
|
abstract String |
getAttributeNamespace(int index)
Returns the namespace URI of the attribute with the given index (starts from 0).
|
abstract String |
getAttributePrefix(int index)
Returns the prefix of the specified attribute Returns null if the element has no prefix.
|
abstract String |
getAttributeType(int index)
Returns the type of the specified attribute If parser is non-validating it MUST return CDATA.
|
abstract String |
getAttributeValue(int index)
Returns the given attributes value.
|
abstract String |
getAttributeValue(String namespace, String name)
Returns the attributes value identified by namespace URI and namespace localName.
|
abstract int |
getColumnNumber()
Returns the current column number, starting from 0.
|
abstract int |
getDepth()
Returns the current depth of the element.
|
abstract int |
getEventType()
Returns the type of the current event (START_TAG, END_TAG, TEXT, etc.)
|
abstract boolean |
getFeature(String name)
Returns the current value of the given feature.
|
abstract String |
getInputEncoding()
Returns the input encoding if known, null otherwise.
|
abstract int |
getLineNumber()
Returns the current line number, starting from 1.
|
abstract String |
getName()
For START_TAG or END_TAG events, the (local) name of the current element is returned when namespaces are enabled.
|
abstract String |
getNamespace()
Returns the namespace URI of the current element.
|
abstract String |
getNamespace(String prefix)
Returns the URI corresponding to the given prefix, depending on current state of the parser.
|
abstract int |
getNamespaceCount(int depth)
Returns the numbers of elements in the namespace stack for the given depth.
|
abstract String |
getNamespacePrefix(int pos)
Returns the namespace prefix for the given position in the namespace stack.
|
abstract String |
getNamespaceUri(int pos)
Returns the namespace URI for the given position in the namespace stack If the position is out of range, an exception is thrown.
|
abstract String |
getPositionDescription()
Returns a short text describing the current parser state, including the position, a description of the current event and the data source if known.
|
abstract String |
getPrefix()
Returns the prefix of the current element.
|
abstract Object |
getProperty(String name)
Look up the value of a property.
|
abstract String |
getText()
Returns the text content of the current event as String.
|
abstract char[] |
getTextCharacters(int[] holderForStartAndLength)
Returns the buffer that contains the text of the current event, as well as the start offset and length relevant for the current event.
|
abstract boolean |
isAttributeDefault(int index)
Returns if the specified attribute was not in input was declared in XML.
|
abstract boolean |
isEmptyElementTag()
Returns true if the current event is START_TAG and the tag is degenerated (e.g.
|
abstract boolean |
isWhitespace()
Checks whether the current TEXT event contains only whitespace characters.
|
abstract int |
next()
Get next parsing event - element content wil be coalesced and only one TEXT event must be returned for whole element content (comments and processing instructions will be ignored and entity references must be expanded or exception mus be thrown if entity reference can not be expanded).
|
abstract int |
nextTag()
Call next() and return event if it is START_TAG or END_TAG otherwise throw an exception.
|
abstract String |
nextText()
If current event is START_TAG then if next element is TEXT then element content is returned or if next event is END_TAG then empty string is returned, otherwise exception is thrown.
|
abstract int |
nextToken()
This method works similarly to next() but will expose additional event types (COMMENT, CDSECT, DOCDECL, ENTITY_REF, PROCESSING_INSTRUCTION, or IGNORABLE_WHITESPACE) if they are available in input.
|
abstract void |
require(int type, String namespace, String name)
Test if the current event is of the given type and if the namespace and name do match.
|
abstract void |
setFeature(String name, boolean state)
Use this call to change the general behaviour of the parser, such as namespace processing or doctype declaration handling.
|
abstract void |
setInput(Reader in)
Set the input source for parser to the given reader and resets the parser.
|
abstract void |
setInput(InputStream inputStream, String inputEncoding)
Sets the input stream the parser is going to process.
|
abstract void |
setProperty(String name, Object value)
Set the value of a property.
|
发表评论
-
android textview 特出显示
2013-04-22 19:40 1644在xml文件中使用android:textStyle=&qu ... -
反编译apk
2013-02-27 10:42 980工具下载:需用到dex2ja ... -
Android 通过字符串来获取R下面资源的ID 值
2013-01-30 14:33 1208方法一: try{ Field field= ... -
android禁止锁屏保持常亮 .
2012-12-26 11:12 4721在播放video的时候在mediaplayer mMedia ... -
Eclipse开发Android的配置(包括ADT安装,SDK配置)
2012-12-08 12:35 18441. 下载Android SDK htt ... -
android 命名规范
2012-12-03 19:16 4154一、Android编码规范 1.java代码中不出现中文 ... -
div+css命名规范 嫁接android xml命名
2012-12-03 19:13 1102CSS命名规则 头:header 内容:co ... -
android 之 Task Activity .
2012-11-27 20:55 2609首先task包含一个或多个activity,它是安排在一个堆栈 ... -
最本质的多线程:hanlder和message机制:
2012-11-27 19:58 1715Android多线程 作者:陈 ... -
android之多线程工作(一)AsyncTask .
2012-11-27 19:35 1339本文章主要讲解下AsyncTa ... -
Android 重要包描述
2012-10-25 13:21 981在Android中,各种包写成android.* 的方式,重要 ... -
android.os.NetworkOnMainThreadException 异常处理
2012-10-20 15:12 1092android.os.NetworkOnMainThreadE ... -
android textview属性
2012-08-24 16:10 857android:autoLink设置是否当 ... -
GestureDetector.OnDoubleTapListener 和 GestureDetector.OnGestureListener
2012-07-20 21:30 2006android.view.GestureDetector. ... -
Android Google Map API的使用(一)
2012-07-17 20:49 1104Android中定义了一个名为com.google.andro ... -
Android中Context简介
2012-07-15 19:20 10378Context字面意思是上下文,位于framework pac ... -
DocumentBuilder API 官方翻译(翻译有错的地方请多指正)
2012-07-04 12:27 1264public abstract class Document ... -
Android开发如何去除标题栏title
2012-07-02 18:18 792Android开发如何去除标题栏title 去除标题栏tit ... -
Android 获取存储卡路径和空间使用情况
2012-07-01 16:55 5719/** 获取存储卡路径 */ File sdc ... -
Problems occurred when invoking code from plug-in: "org.eclipse.core.resources".
2012-06-30 17:25 7589今天在写一个小例子时,处了一个错误让我找了一下午,下面是错误代 ...
相关推荐
XmlPullParser是Android系统提供的一种解析XML文件的API,它是一种基于事件驱动的解析方式,能够高效、节省资源地处理XML文档。在这个“XmlPullParser解析Xml文件解析demo”中,我们将探讨如何利用XmlPullParser来...
XMLPullParser是Android开发中用于解析XML文档的一种高效且节省内存的方法。它提供了一种事件驱动的解析模型,允许开发者逐个处理XML文档的元素,而不是一次性加载整个文档到内存中,这对于处理大体积的XML数据尤其...
XmlPullParser是Android开发中用于解析XML文档的一种高效且节省资源的工具。它的主要作用是将XML数据流解析成一个个事件,如开始标签、结束标签、文本等,开发者可以通过监听这些事件来处理XML内容,而无需一次性...
XmlPullParser 是一个解析XML文档的轻量级拉式解析器,它在Android系统中被广泛使用,用于高效地处理XML数据。尽管它最初是为移动设备优化的,但它的功能和效率使其同样适用于Java Standard Edition (Java SE)环境。...
XMLPullParser解析器是Android系统中用于处理XML文档的解析库,它是基于事件驱动的解析模型。这个jar包包含了处理XML数据的关键类,如XmlPullParser、XmlPullParserFactory、XmlSerializer和XmlPullParserException...
为了高效地解析XML,Android提供了多种方式,其中XmlPullParser是一个非常重要的解析工具。本篇文章将详细探讨如何在Android中使用XmlPullParser来解析XML文件,并通过一个具体的WeiboTest示例进行说明。 首先,...
怎么用XmlPullParser解析xml,以及怎么把数据转换成xml。
XmlPullParser.newInstance的相关jar
在学习Android的Framework层源码时,Android大量的使用XmlPullParser来解析xml文件的源码。因此,这里也顺道介绍一下XmlPullParser的使用。 XML XML(eXtensible Markup Language)中文名为可扩展标记语言。标记指...
在Android开发中,处理XML数据时,`XmlPullParser`是一种高效且节省内存的解析方式。它是基于事件驱动的解析器,可以逐行读取XML文档,通过监听各种事件(如开始文档、开始标签、结束标签等)来解析XML内容。这种...
进来很多人在找天气的API接口,所以乘此机会写了个在android平台用 XmlPullParser解析从车联网(即百度天气API)获取的天气XML文件!这是一个工具包,开发者可以直接拿过去调用,其中为了省时间,很多代码没优化,如...
XmlPullParser parser = factory.newPullParser(); 3.设置解析文件 parser.setInput(new FileInputStream(new File("res/book.xml")), "UTF-8"); 4.第一个解析事件 int eventType = paser.getEventType(); 5...
1. **创建PullParser对象**:首先,你需要通过`XmlPullParserFactory`工厂类创建一个`XmlPullParser`实例。通常,你会选择`newInstance()`方法,并设置解析器类型为非Namespace感知的XML解析器。 2. **设置输入源**...
大家好,请参考此代码进行android应用程序编程中的XML解析,该应用程序使用从远程服务器/主机访问的xml格式输出数据,对初学者来说非常好,它使用XML Pull Parser解析数据并将其显示在listview中,点击任何项目,它...
然而,在混淆过程中可能会遇到各种问题,如本例中的“android4.0混淆XmlPullParser报错”。这个问题发生在开发者在`proguard-project.txt`配置文件中添加了`-libraryjars`指令,指向了一个包含ksoap2-android库的...
描述一个基于XmlPullParser的,针对RSS的android异步xml处理器。版本号入门(V1.0.0) 在build.gradle中添加依赖项(App模块) compile 'com.eukaprotech.xmlprocessor:xmlprocessor:1.0.0@aar' 用法(V1.0.0) 处理...
`XmlPullParser`是一个解析XML文档的接口,它提供了一种高效且灵活的方式来处理XML数据。本教程将深入探讨如何利用`XmlPullParser`来解析Android中的布局文件,通过查看日志(logging)来追踪解析过程。 首先,`...