最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
jsp 增加,删除,读取xml文件中指定标记的内容代码
时间:2022-06-29 00:43:28 编辑:袖梨 来源:一聚教程网
网页特效p/jsp.html target=_blank >jsp教程 增加,删除,读取xml文件中指定标记的内容代码
package xml;
import java.io.file;
import java.util.list;import org.dom4j.document;
import org.dom4j.documentexception;
import org.dom4j.element;
import org.dom4j.qname;
import org.dom4j.io.saxreader;public class dom4jtest {
private saxreader reader;
private document document;
private static string path = "c:/dom4jsample1.xml";public dom4jtest(string str) throws documentexception {
reader = new saxreader();
document = reader.read(new file(str));
}public static void main(string[] args) throws documentexception {
// todo auto-generated method stub
dom4jtest test = new dom4jtest(path);
test.getinfo();}
public void getinfo() {
element root = document.getrootelement();qname qname = new qname("ip");
listlist = root.elements(qname); for (int i = 0; i < list.size(); i++) {
system.out.println(list.get(i).gettext());
}}
}
public void add(string add) throws ioexception {
element root = document.getrootelement();
element e = root.addelement("ip");
e.settext(add);
writefile(document);
}// 写入文件
private void writefile(document doc) throws ioexception {
filewriter out = new filewriter(path);
doc.write(out);
out.flush();
out.close();
}
相关文章
- 逆水寒手游琥珀氽鲜汤配方与材料获取方法一览 07-02
- 会是神作吗?任天堂确认咚奇刚新作有马里奥奥德赛团队成员参与制作! 07-02
- 曙光重临玄武玩法指南 07-02
- 炉石传说OTK星舰瞎卡组构筑推荐 07-02
- PS怎么设置玻璃扭曲效果 ps给草莓制作玻璃模糊效果教程 07-02
- 币圈:OKX DEX突然暂停服务:黑客到底是如何洗钱的? 07-02