欢迎来到天天文库
浏览记录
ID:30768969
大小:51.00 KB
页数:17页
时间:2019-01-03
《java操纵xml文件的读写,并根据xml生成树型菜单》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、进口java.uti1.Iterator;进口并不知道;进口.io.;进口org.jdom.Document;进口org.jdom・Element:进口org.jdom・input・SAXBuilder;进口com.ldtec.todayReport・datao;@author乔TODO更改生成的类型注释的模板窗口-首选项-Java-代码样式-代码模板/公开课XMLTodayReportPar{私有静态最后字符串TODAYREPORTS=“TODAYREPORTS”;私有静态最后字符串TODAYREPORT二“TODAYREPORT”;私有静态最终字符串ID=
2、"ID"•、私有静态最终字符串名称二“名称”;私有静态最终字符串报告二“报告”;私有静态最终字符串TABLENAME二〃TABLENAME〃;私有静态最终字符串描述二"DESCRIPTION〃;私有的静态最后的字符串头二”HEAD"•、私有静态最终字符串BODY二〃BODY〃;私有静态最后字符串统计二“统计”;私有静态最终字符串向前二〃FORWARD〃;私有静态最终字符串URL二〃URL〃;私有静态XMLTodayReports报告二null;/返回所有的表字符串realpath二〃“;公共XMLTodayReportsgetXMLTodayReports(字
3、符串realpath){这一点。realpath二realpath;如果(xmltodayReports!二null)返回xmltodayReports;其他{xmltodayReports二newxmltodayReports();尝试{SAXBuilderbuilder二newSAXBuilder();//注册解析器根元素二零;字符串路径二realpath+"web-inf\todayReport\todayReportoxml”;//字符串路径二"D:\开发\TOMCAT\webapps\rebi\web-inf\i2conf\tod
4、ayReport\todayReport.xml”;system・out。println(agetrealpath二"+路径);//文档doc=builder,build(XMLTodayReports・getClass()・getResourceAsStrea・・\・\・・\・\・・\i2conf\\ReportDefine.xml报告”));文档doc二建设者。构建(新文件(路径));//创建文档,读入XML文件根二doc.getRootElement();getTodayReports(根,xmltodayReports);返回xmlto
5、dayReports;}捕获(异常e){e.printStackTrace();}返回null;}}/根据表名返回要找的报表信息。@param表@returnXMLTable公共XMLTodayReportgetXMLTodayReport(字符串id){如果(id!二…){返回(XMLTodayReport)getXMLTodayReports(realpath).getTodayReportBylD(id);}其他返回null;}/返回TodayReport信息@return/公共列表getAllValue(){返回(列表)getXMLTodayRepor
6、ts(realpath)。getAllValue();@paramtodayReportsElem@paramxmltodayReports/公共voidgetTodayReports(tgMtodayReportsElem,XMLTodayReportsXMLTodayReports){列表todayReportList二todayReportsElem.getChildren(TODAYREPORT);for(迭代器二todayreportlist・Iterator();hasnext();元素todayReportEle=(Element)・next()
7、;XMLTodayReport的XMLTodayReport二newXMLTodayReport();getTodayReport(todayReportElexmltodayReport);xmltodayReports・addXMLTodayReport(xmltodayReport);@paramtodayReportElem@paramxmltodayReport/公共voidgetTodayReport(元素todayReportElem,XMLTodayReportXMLTodayReport){xmltodayReport・setID(today
8、ReportElem.getAttri
此文档下载收益归作者所有