解析xml檔案

2021-08-30 20:46:08 字數 1362 閱讀 7630

1.匯入dom4j.jar;

2.主**:

<1>查詢xml檔案的資料:

(1)public void par***ml() throws documentexception

system.out.println(str[0]+ "的性別:" + str[1] +","+ str[0]+ "的年

齡:" + str[2]);}}

(2)list persons = root.elements();//root同於上面的root

for (object person : persons)

system.out.println(str[0] + "的性別:" + str[1] + "," + str[0] + "的

年齡:"+ str[2]);}}

(3)public void par***ml2() throws documentexception

});}

<4>建立xml檔案

public void createdoc() throws ioexception

<5>向xml檔案新增資料:

public void addelement(element e) throws exception

<6>修改xml檔案

(1)public void updateelement() throws documentexception

try catch (ioexception e1)

}});

}(2)匯入jaxen-1.1.1.jar;

(3)public void updateelement2() throws documentexception, ioexception

}outputformat of = outputformat.createprettyprint();

of.setencoding("gbk");

xmlwriter xw = new xmlwriter(new filewriter("src/person.xml"), of);

xw.write(doc);

xw.close();

}(4)新增屬性:

public void addattribute() throws exception

outputformat of = outputformat.createprettyprint();

of.setencoding("gbk");

xmlwriter xw = new xmlwriter(new filewriter("src/person.xml"), of);

xw.write(doc);

xw.close();

}

建立xml檔案 解析xml檔案

import codecs import xml.dom.minidom doc xml.dom.minidom.document print doc root doc.createelement booklist print u 新增的xml標籤為 root.tagname root.setatt...

解析XML檔案

sax解析xml 得到saxparse ctory saxparse ctory saxparse ctory saxparse ctory.newinstance 得到saxparser saxparser saxparser saxparse ctory.newsaxparser 得到xmlre...

XML檔案解析

xml是可擴充套件標記語言,用來傳輸和儲存資料。xml文件必須包含根元素,該元素是所有其他元素的父元素。xml文件中的元素形成了樹形結構。xml有以下特點 建立名稱是 textfile1.txt 的文件,設定屬性 複製到輸出目錄 如果較新則複製 在工程執行時,會自動將該txt檔案複製到bin下面。2...