java讀取xml文件內(nèi)容 java修改xml文件內(nèi)容?
java修改xml文件內(nèi)容?代碼如下:導(dǎo)入org.jdom公司*導(dǎo)入org.jdom.output輸出*導(dǎo)入org.jdom.input輸入*導(dǎo)入java.io文件.*公共類xml{public vo
java修改xml文件內(nèi)容?
代碼如下:導(dǎo)入org.jdom公司*導(dǎo)入org.jdom.output輸出*導(dǎo)入org.jdom.input輸入*導(dǎo)入java.io文件.*公共類xml{public void toXml()拋出JDOMException,IOException{SAXBuilder SAXBuilder=new SAXBuilder(false)saxBuilder.setExpandEntities文件(false)File File=新文件(“c:測試.xml)文件=saxBuilder.build版本(新建)文件(“c:測試.xml)元素元素=文檔getRootElement()//系統(tǒng)輸出打印(元素toString())元素getChild(“Collectors”).getChild(“Collector”).getAttribute(“HostIP”).setValue(“192.168.0.1”)元素getChild(“Collectors”).getChild(“Collector”).getAttribute(“PortID”).setValue(“100000”)Element elem1=(Element)元素克隆()文件Doc=new Document(elem1)XMLOutputter XMLOut=new XMLOutputter()XMLOut.setEncoding(“BIG5”)XMLOut.setNewlines(正確)文件.刪除()XMLOut.output輸出(Doc,new FileOutputStream(“c:test”“.xml”)}公共靜態(tài)void main(字符串a(chǎn)rgs[]){xml x=new xml()try{x.toXml()}catch(異常e){}}}