-<学生花名册>"> -<学生花名册>" />
android读写XML 收藏

android读写XML 收藏

ID:39801988

大小:63.50 KB

页数:12页

时间:2019-07-11

android读写XML 收藏_第1页
android读写XML 收藏_第2页
android读写XML 收藏_第3页
android读写XML 收藏_第4页
android读写XML 收藏_第5页
资源描述:

《android读写XML 收藏》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库

1、android读写XML收藏input.xml文件存放学生信息viewplaincopytoclipboardprint?-<学生花名册>-<学生性别="男"><姓名>吴凤龙<年龄>30<电话>68888888-<学生性别="男"><姓名>张井满<年龄>32<电话>88888888

2、"UTF-8"standalone="no"?>-<学生花名册>-<学生性别="男"><姓名>吴凤龙<年龄>30<电话>68888888-<学生性别="男"><姓名>张井满<年龄>32<电话>88888888读取XML的代码:viewplaincopytoclipboardprint?privateArrayListreadSMSXMLFile(Stringpath,Stringfilename){FileinFil

3、e=newFile(path,filename);try{inFile.createNewFile();}catch(IOExceptione){e.printStackTrace();}//为解析XML作准备,创建DocumentBuilderFactory实例,指定DocumentBuilderDocumentBuilderFactorydbf=DocumentBuilderFactory.newInstance();DocumentBuilderdb=null;try{db=dbf.newDocumentBuilder()

4、;}catch(ParserConfigurationExceptionpce){System.err.println(pce);//出异常时输出异常信息,然后退出,下同System.exit(1);}Documentdoc=null;try{doc=db.parse(inFile);}catch(DOMExceptiondom){System.err.println(dom.getMessage());System.exit(1);}catch(IOExceptionioe){System.err.println(ioe);S

5、ystem.exit(1);}//下面是解析XML的全过程,比较简单,先取根元素"学生花名册"Elementroot=doc.getDocumentElement();//取"学生"元素列表NodeListstudents=root.getElementsByTagName("学生");for(inti=0;i

6、entBean=newStudentBean();//取学生的性别属性studentBean.setSex(student.getAttribute("性别"));//取"姓名"元素,下面类同NodeListnames=student.getElementsByTagName("姓名");if(names.getLength()==1){Elemente=(Element)names.item(0);Textt=(Text)e.getFirstChild();studentBean.setName(t.getNodeValue(

7、));}NodeListages=student.getElementsByTagName("年龄");if(ages.getLength()==1){Elemente=(Element)ages.item(0);Textt=(Text)e.getFirstChild();studentBean.setAge(Integer.parseInt(t.getNodeValue()));}NodeListphones=student.getElementsByTagName("电话");if(phones.getLength()==1

8、){Elemente=(Element)phones.item(0);Textt=(Text)e.getFirstChild();studentBean.setPhone(t.getNodeValue());}student_Vector.add(student

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。