



下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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年建筑工地劳务承包合同协议
- 19.急性中毒患者急救与团队处置考核
- 10.创伤性休克患者损伤控制性复苏协作考核
- 档位招租合同(标准版)
- 工程售后服务方案及保证措施(范文)
- 2025年人教版高中英语宾语从句练习题30题带答案
- 2025年人教版高二英语名词性从句练习题50题【含答案解析版】
- 2025年湖北省公路水运工程施工企业安管人员考试(主要负责人A类)水路工程经典试题及答案
- 解析卷人教版八年级物理上册第5章透镜及其应用专项攻克试卷(含答案详解版)
- 中国蛇伤救治指南2024
- 勤劳的小蜜蜂课件
- 2024年青岛市市属事业单位遴选考试真题
- 自体输血管理制度与技术规范
- 《电商平台提价运营策略对比分析-以拼多多与淘宝特价版为例》12000字
- 2024秋七年级英语上册 Unit 3 Is this your pencil Period 1 Section A (1a-1c)教学实录(新版)人教新目标版
- 《神经外科手术的麻醉》课件
- 2025年上半年泸州市纳溪区总工会招考社会化专职工会工作者易考易错模拟试题(共500题)试卷后附参考答案
- 网格员安全知识培训课件
- GB/T 15972.40-2024光纤试验方法规范第40部分:传输特性的测量方法和试验程序衰减
- 法院冻结所有账户执行异议申请书
评论
0/150
提交评论