資源簡介
孫鑫老師的Java Web開發(fā)詳解里面所有的示例代碼

代碼片段和文件信息
import?java.io.File;
import?java.io.FileWriter;
import?java.io.IOException;
import?java.io.UnsupportedEncodingException;
import?java.util.List;
import?java.util.Iterator;
import?javax.xml.parsers.*;
import?org.dom4j.*;
import?org.dom4j.io.SAXReader;
//import?org.dom4j.io.DOMReader;
import?org.dom4j.io.OutputFormat;
import?org.dom4j.io.xmlWriter;
import?org.xml.sax.SAXException;
public?class?Dom4jTest
{
????public?static?void?main(String[]?args)
????{
????????SAXReader?saxReader=new?SAXReader();
????????File?file=new?File(“students.xml“);
????????DocumentBuilderFactory?dbf=DocumentBuilderFactory.newInstance();
????????try
????????{
????????????Document?doc=saxReader.read(file);
????????????
????????????/*DocumentBuilder?db=dbf.newDocumentBuilder();
????????File?file=new?File(“students.xml“);
????????org.w3c.dom.Document?document=db.parse(file);
????????DOMReader?domReader=new?DOMReader();
????????org.dom4j.Document?doc=domReader.read(document);*/
????????//doc.normalize();
????????//doc.accept(new?MyVisitor());
????????Element?root=doc.getRootElement();
????????for?(java.util.Iterator?i=root.elementIterator();i.hasNext();?)
????????????{
???? ????????Element?element?=?(Element)?i.next();
????????System.out.println(element.getName());
????????}
????????????//------------------添加節(jié)點------------------
????????????//創(chuàng)建表示一個學(xué)生信息的各元素節(jié)點
????????????/*Element?eltStu=DocumentHelper.createElement(“student“);
????????????Element?eltName=DocumentHelper.createElement(“name“);
????????????Element?eltAge=DocumentHelper.createElement(“age“);*/
????????????
????????????//Element?root=doc.getRootElement();
????????????/*List?l=root.elements(“student“);
????????????System.out.println(“size=“+l.size());
????????????System.out.println(l.get(0));
????????????System.out.println(l.get(1));*/
????????????/*Element?eltStu=root.element(“student“);
????????????System.out.println(eltStu);*/
????????????
????????????/*for?(java.util.Iterator?i=root.elementIterator();i.hasNext();?)
????????????{
????????????????Element?element?=?(Element)?i.next();
????????????????System.out.println(element);
????????????}*/
????????????/*Element?eltStu=root.element(“student“);
????????????//root.remove(eltStu);
????????????boolean?b=eltStu.remove?(eltStu.attribute(“sn“));
????????????
????????????//Attribute?attr=(Attribute)attrList.get(0);
????????????System.out.println(b);*/
????????????
????????????/*OutputFormat?outFmt=OutputFormat.createPrettyPrint();
????????????outFmt.setEncoding(“GBK“);
????????????outFmt.setIndent(“????“);
????????????
????????????//FileWriter?fw=new?FileWriter(“test.xml“);
????????????xmlWriter?xmlWriter=new?xmlWriter(outFmt);
????????????
????????????xmlWriter.write(doc);*/
????????????
????????????/*for?(java.util.Iterator?i=l.iterator();i.hasNext();?)
????????????{
????????????????//Attribute?attr=(Attribute)i.next();
????????????????//System.out.println(attr.
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
????.CA....???????155??2004-12-31?03:30??Java?Web開發(fā)詳解源碼\AppendixA\FirstPage.html
????.CA....??????2220??2005-11-10?17:46??Java?Web開發(fā)詳解源碼\AppendixA\form.html
????.CA....???????446??2005-08-09?21:56??Java?Web開發(fā)詳解源碼\AppendixA\li
????.CA....??????4060??2004-06-28?03:44??Java?Web開發(fā)詳解源碼\AppendixA\logo.gif
????.CA....???????242??2005-01-08?21:52??Java?Web開發(fā)詳解源碼\AppendixA\SecondPage1.html
????.CA....???????311??2005-11-09?19:46??Java?Web開發(fā)詳解源碼\AppendixA\SecondPage2.html
????.CA....???????434??2005-11-09?21:42??Java?Web開發(fā)詳解源碼\AppendixA\SecondPage3.html
????.CA....???????470??2005-01-08?21:57??Java?Web開發(fā)詳解源碼\AppendixA\SecondPage4.html
????.CA....???????420??2005-01-01?22:14??Java?Web開發(fā)詳解源碼\AppendixA\SecondPage5.html
????.CA....???????446??2005-08-09?18:45??Java?Web開發(fā)詳解源碼\AppendixA\SecondPage6.html
????.CA....??????1016??2005-01-02?01:55??Java?Web開發(fā)詳解源碼\AppendixA\table.html
????.CA....???????133??2005-08-04?16:43??Java?Web開發(fā)詳解源碼\ch01\例1-1(HelloWorld).html
????.CA....???????247??2005-08-10?19:45??Java?Web開發(fā)詳解源碼\ch01\例1-10.xm
????.CA....???????397??2005-08-10?19:45??Java?Web開發(fā)詳解源碼\ch01\例1-11.xm
????.CA....???????189??2005-08-10?19:46??Java?Web開發(fā)詳解源碼\ch01\例1-12.xm
????.CA....???????342??2005-08-10?19:46??Java?Web開發(fā)詳解源碼\ch01\例1-13.xm
????.CA....???????230??2005-11-18?19:50??Java?Web開發(fā)詳解源碼\ch01\例1-14(website).dtd
????.CA....???????166??2005-10-17?20:09??Java?Web開發(fā)詳解源碼\ch01\例1-14(website).xm
????.CA....???????341??2005-08-10?19:47??Java?Web開發(fā)詳解源碼\ch01\例1-15(website2).xm
????.CA....???????339??2005-11-18?23:11??Java?Web開發(fā)詳解源碼\ch01\例1-16.xm
????.CA....???????383??2005-11-18?23:11??Java?Web開發(fā)詳解源碼\ch01\例1-17.xm
????.CA....???????525??2005-08-10?19:48??Java?Web開發(fā)詳解源碼\ch01\例1-18.xm
????.CA....???????352??2005-08-10?19:49??Java?Web開發(fā)詳解源碼\ch01\例1-19(company).xm
????.CA....???????130??2005-08-04?16:43??Java?Web開發(fā)詳解源碼\ch01\例1-2(HelloWorld).xm
????.CA....???????468??2005-08-10?19:50??Java?Web開發(fā)詳解源碼\ch01\例1-20-1.xm
????.CA....???????517??2005-08-10?19:50??Java?Web開發(fā)詳解源碼\ch01\例1-20-2.xm
????.CA....???????892??2005-08-09?00:07??Java?Web開發(fā)詳解源碼\ch01\例1-21(library).xm
????.CA....???????892??2005-08-10?19:50??Java?Web開發(fā)詳解源碼\ch01\例1-21.xm
????.CA....???????313??2005-08-10?19:51??Java?Web開發(fā)詳解源碼\ch01\例1-22.xm
????.CA....???????420??2005-08-04?16:54??Java?Web開發(fā)詳解源碼\ch01\例1-3(SecondPage5).html
............此處省略685個文件信息
評論
共有 條評論