res/xml中的XML文件会被Android平台(如果使用Eclipse)自动提取并编译为资源。
在程序中可能通过Android支持的XML格式来读取它。
people.xml文件
<people>
<personfirstname="hu"lastname="bing"/>
<personfirstname="hu"lastname="dashi"/>
<personfirstname="zheng"lastname="wei"/>
</people> 代码片段
void readXmlFile()
{
XmlPullParserparser=this.getResources().getXml(R.xml.people);
Stringname=null;
Stringfirst=null;
Stringlast=null;
StringattrName=null;
StringattrValue=null;
try {
while(parser.next()!=XmlPullParser.END_DOCUMENT)
{
name=parser.getName();
first=null;
last=null;
if( (name!=null)&&name.equals("person"))
{
intsize=parser.getAttributeCount();
for (inti=0;i<size;i++)
{
attrName=parser.getAttributeName(i);
attrValue=parser.getAttributeValue(i);

if (attrName!=null)
{
if ( attrName.equals("firstname") )
{
first=attrValue;
}
elseif ( attrName.equals("lastname") )
{
last=attrValue;
}
}
}
if (first!=null&&last!=null)
Log.i(tag,first+last);
}
}
} catch (XmlPullParserExceptione)
{
Log.i(tag,"Xmlerro",e);
}
catch (IOExceptione)
{
Log.i(tag,"IOerro",e);
}

}

更多相关文章

  1. NPM 和webpack 的基础使用
  2. 【阿里云镜像】使用阿里巴巴DNS镜像源——DNS配置教程
  3. 读取android手机流量信息
  4. android 使用html5作布局文件: webview跟javascript交互
  5. Android(安卓)多媒体扫描过程(Android(安卓)Media Scanner Proces
  6. android“设置”里的版本号
  7. Android开发环境搭建
  8. Android(安卓)Resource介绍和使用
  9. 2014.01.21 ——— android 关联android-support源码

随机推荐

  1. Android进阶 ——— Android官方架构组件
  2. Android各版本代号和API级别对照表
  3. android Sqlitedatabase 应用
  4. Android(安卓)VideoView实现视频播放
  5. Android(安卓)build常见Error
  6. android利用JNI调用C++自定义类
  7. 最牛逼android上的图表库MpChart(一) 介绍
  8. Android界面编程——Android基本控件
  9. Android兼容性问题 -- FrameLayout中View
  10. Google Android开发精华教程