预览加载中,请您耐心等待几秒...
1/6
2/6
3/6
4/6
5/6
6/6

在线预览结束,喜欢就下载吧,查找使用更方便

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

jdom解析xml (2010-05-2510:36:46) HYPERLINK"javascript:;"转载▼ 标签: HYPERLINK"http://search.sina.com.cn/?c=blog&q=jdom&by=tag"\t"_blank"jdom HYPERLINK"http://search.sina.com.cn/?c=blog&q=%BD%E2%CE%F6&by=tag"\t"_blank"解析 HYPERLINK"http://search.sina.com.cn/?c=blog&q=xml&by=tag"\t"_blank"xml HYPERLINK"http://search.sina.com.cn/?c=blog&q=java&by=tag"\t"_blank"java分类:HYPERLINK"http://blog.sina.com.cn/s/articlelist_1742342267_5_1.html"\t"_blank"技术摘要packagebean; importjava.io.FileInputStream;importjava.io.FileNotFoundException;importjava.io.FileOutputStream;importjava.io.IOException;importjava.io.InputStream;importjava.io.OutputStream;importjava.util.List; importorg.jdom.Document;importorg.jdom.Element;importorg.jdom.JDOMException;importorg.jdom.input.SAXBuilder;importorg.jdom.output.XMLOutputter; publicclassXmlParse{ //解析xml文件publicstaticvoidXmlParse()throwsJDOMException,IOException{SAXBuilderbuilder=newSAXBuilder();InputStreamfile=newFileInputStream("src/xml/po.xml");Documentdocument=builder.build(file);//获得文档对象Elementroot=document.getRootElement();//获得根节点List<Element>list=root.getChildren();for(Elemente:list){System.out.println("ID="+e.getAttributeValue("id"));System.out.println("username="+e.getChildText("username"));System.out.println("password="+e.getChildText("password"));}}//增publicstaticvoidaddXml()throwsJDOMException,FileNotFoundException,IOException{SAXBuilderbuilder=newSAXBuilder();Documentdoc=builder.build("src/xml/po.xml");//获得文档对象Elementroot=doc.getRootElement();//获得根节点//添加新元素Elementelement=newElement("person");element.setAttribute("id","3");Elementelement1=newElement("username");element1.setText("zhangdaihao");Elementelement2=newElement("password");element2.setText("mima");element.addContent(element1);element.addContent(element2);root.addContent(element);doc.setRootElement(root);//文件处理XMLOutputterout=newXMLOutputter();out.output(doc,newFileOutputStream("src/xml/po.xml"));}//根据ID值删除一个节点publicstaticvoiddeletePerson(intid)throwsJDOMException,IO