



下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、一。constant.java 文件:public class constant public public public public public public public public publicstaticstaticstaticstaticstaticstaticstaticstaticstaticstringstringstringstringstringstringstringstringstringrs s_dom_root_t j: tle = n/channel/t irss_dom_r00t_link = n/channel/link"rss_dom_chi
2、ldren_root = n/channel/itemn;rss_dom_children_roo t_ ti tle =rss_dom_children_roo t_l ink = nlinkit;rss_dom_ch1:ldren_root_pubdate = npubda te”;r ss_dom_children_ r00 t_type = "type*;“id”;rss dom children root id =rss dom children root description ="description"二。xmldom4j.java 文件:写入文件
3、d:/qqq.xmlimport org.dom4j.document;import org.dom4j.documenthelper;import org.dom4j.element;import org.dom4j.io.xmlwriter;import java.io.*;public class xmldom4jpublic void generatedocument()document document = documenthelper.createdocument();element catalogelement = document.addelementc'catalog
4、1'); catalogelement.addcomment(,an xml catalog11);catalogeleme nt.addprocessi ngln structi ontarget't'text1');element journalelement = catalogelement.addelementcjournat1); journalelement.addattribute("title", "xml zone*'); journalelement.addattribute("publishe
5、r", "ibm developerworks");element articleelement二journalelement.addelementrarticle1'); articleelement.addattributec'level", "intermediate"); articleelement.addattribute("date", "december-2001");eleme nt titleelement=articleeleme nt.addeleme n
6、t(”title”); titleelement.settext(”java configuration with xml schema'*);element authorelement=articleelement.addelement(”authol);element firstnameelement=authorelement.addeleme nt(”first name”);firstnameelement.settext(,marcello,');element lastnameelement二authorelement.addelementlastname”);
7、lastnameelement.settext("vitalettin);tryxmlwriter output = new xmlwriter(new filewriter( new file("d:/qqql.xml"); output.write( document);output.close();catch(ioexception e)system.out.pri ntln (e.getmessage();public static void main(string args)xmldom4j dom4j=new xmldom4j();dom4j.ge n
8、eratedocume nt();三。xmlparse. java 文件:import javaiofile;import javaio.filewriter;import javaioioexception;import javaneturl;import java.text.simpledateformat;import javautdate;import javautiliterator;import java.util.list;import org.dom4 jdocument;import org.dom4 jdocumenthelper;import org.dom4 jelem
9、ent;import orgdom4 jnode;import orgdom4 j.io.xmlwriter;public class xmlparse / * param args*/public static void main(string args) xmlutils xu = new xmlutils();url url;try url = newurl (11 http: /www. hl jdlys . gov cn/rss_f eed/xzzf_nodate xmln );list<?> list = xu.getxmllnfo(constantrss_dom_ch
10、ildren_root url);document document = documenthelper.createdocument();/element elementroot = (element) listiterator () next (); node noderoottitle =elementroot.selectsinglenode(constant.rss_dom_root_title);node noderootlink =elementroot.selectsinglenode(constantrss_dom_root_link);element channeleleme
11、nt = document addelement (l!channel,t); element titleelement = channelelementaddelement("titlen); titleelementsettext(noderoottitlegettext ();/element linkelement = channelelement. addelement (lflink,f); linkelementsettext(noderootlinkgettext();for (iterator<?> iter = list.iterator (); it
12、er.hasnext();) element element = (element) iter.next();node nodet=elementselectsinglenode(constantrss_dom_children_root_title);node nodelink =elementselectsinglenode(constantrss_dom_children_root_link);node nodepubdate =elementselectsinglenod©(constantrss_dom_children_root_pubdate);node nodetyp
13、e =elementselectsinglenode(constantrss_dom_children_root_type);node nodeld =elementselectsinglenode(constantrss_dom_children_root_id);node nodedescription =element.selectsinglenode(constant.rss_dom_children_root_description);/system, out .printin (element. attributevalue (hversionh ) ) ; /获取)阪本 elem
14、ent itemelement = channelelement. addelement ( h item11); element cldtitleelement =itemelementaddelement("title”);cldtitleelementsettext(nodetitlegettext() ) ;/element cldlinkelement = itemelement.addelement(hlinkn); cldlinkelementsettext(nodelinkgettext();element pubdateelement =itemelementadd
15、element(npubdaten);pubdateelementsettext(nodepubdatqgettext();tryelement typeelement = itemelement.addelement(htypeh);typeelementsettext(nodetypegettext ();catch(nullpointerexception e)element idelement = itemelementaddelement("id”); idelementsettext(nodeidgettext();element descriptionelement =
16、itemelementaddelement("description”);descriptionelementsettext(nodedescription.gettext(); /trydate time = new date ();simpledateformat sdf = newsimpledateform且t(hyyyy-mm-dd-hh-mm-ss");string nowtime = sdf.format(time);/system.out.printin(nowtime);string f ilename = nowtime + 11. xml,f;xmlwriter output = new xmlwri
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 阀门工程师(球阀)考试试卷及答案
- 2025年健腹椅项目合作计划书
- 2025年地质勘探和地震专用仪器项目合作计划书
- 2025年山西省政府研究室下属事业单位招聘考试笔试试题【答案】
- 2025年事业单位招聘考试公共基础知识模拟试卷题库(三套)【答案】
- 2025年中新天津生态城教育系统招聘教职人员考试试题【答案】
- 消费趋势与地区差异分析:新型消费模式与市场动态
- 消防月消防知识竞赛选题库6
- 老龄员工工作述职报告范文
- 箱梁预制场建设施工方案
- 2024四川广元市检察机关招聘聘用制书记员22人笔试备考题库及答案解析
- 二维材料在柔性电子中的应用研究
- 内科患者VTE风险评估表
- 一年级上册美术教案-第1课 让大家认识我:诚实最好 ▏人美版
- 科学认识天气智慧树知到期末考试答案2024年
- (高清版)DZT 0064.15-2021 地下水质分析方法 第15部分:总硬度的测定 乙二胺四乙酸二钠滴定法
- 心理体检收费目录
- 雅鲁藏布江米林-加查段沿线暴雨泥石流危险度评价的中期报告
- 抗生素的正确使用与合理配比
- 读书分享读书交流会《局外人》课件
- 第十六章-常见骨关节疾病评定技术-2肩周炎评定
评论
0/150
提交评论