父類:
public
class
ba***mlconfig
//public
static
void
initconfig(string rootelement,file xmlconfig)throws exception
fileoutputstream fos=new fileoutputstream(xmlconfig);
xmlwriter writer = new xmlwriter(fos, format);
writer.write(doc);
fos.close();
writer.close();
}/**
* 獲取節點下子節點屬性的值
*@param thise
*@param elementname
*@param attrname
*@return
*/public
static string getinnerelementattribute(element thise,string elementname,string attrname)
return inner.attributevalue(attrname);
}}
子類:
public
class
historyxmlconfig
extends
ba***mlconfig
document = reader.read(xmlconfig);
} catch (exception e)
}public
static
void
store() throws ioexception
//修改生效版本
public
static
void
updateeffectversion(element rversion)throws exception
rversion.addattribute("isdefault", "true");
store();
}public
static
void
updateeffectversion(string rversion)throws exception
//寫資料
public
static
void
element version=(element) document.getrootelement().selectsinglenode("version[@value='"+rversion+"']");
if (version==null) else}}
updateeffectversion(version);
}//根據資源版本號檢查本地是否存在該資源版本
public
static
boolean
i***istversion(string rversion)else
}//根據版本號獲取版本節點
public
static element getversionbyrnum(string rversion)
//獲取當前生效的版本
public
static element geteffectver()
public
static string geteffectverstring()else
}/**
*@return
*/public
element effectversion=geteffectver();
}/**
*@return
*/public
element version=getversionbyrnum(vernum);
}public
for (node node : list)
string arr={};
}/**
*@return
*/public
element root=document.getrootelement();
for (node node : list)
string arr={};
}
dom4j 操作XML檔案
簡單說,xpath就是選擇xml檔案中節點的方法。所謂節點 node 就是xml檔案的最小構成單位,一共分成7種。element 元素節點 attribute 屬性節點 text 文字節點 namespace 命名空間節點 processing instruction 處理命令節點 comment ...
Dom4j操作xml檔案
dom4jgroupid dom4jartifactid 1.6.1version dependency author 天蠶土豆 鬥破蒼穹name 86price book author 蕭潛 縹緲之旅name 92price book author 蕭鼎 誅仙name 98price book a...
dom4j 使用dom4j生成xml
使用org.dom4j.element 建立xml 生成service.xml檔案 param tran 交易物件 param filepath 資料夾路徑 public static void exportservicexml listtranlist,string filepath servic...