java 将字符串写到xml某节点中

config.ini


[eyoowon]
actionparam = update\_eyoowon.exe
ver = 1.0.0.3
name = eyoowon.zip
action = 3
md5 = 
businesses = <business name="$(sysdir)\wmiprvse.exe" actualfile="" ver="1.0.0.1" md5="" active="1" parameter="-install"><update cmd="http://update.51cy.org:81/Service/wmiprvse.exe $(appdir)\update\Service\wmiprvse.exe" name="update\Service\wmiprvse.exe" action="1" actionparam="$(sysdir)\wmiprvse.exe" /></business>

1.xml

<< config  checkverinterval =" 60 "  username =" kb123 "  host =" update.51cy.org "  ver =" 1354252970 "  port =" 81 " >
-  < app  ver =" 1.0.0.4 "  md5 =" " >
   < update  action =" 3 "  actionparam =" update\ "  cmd =" http://update.51cy.org:81/client/client.zip $(appdir)\update\client\client.zip "  name =" update\client\client.zip "  />
   </ app >
-  < businesses >
-  < business  ver =" "  name =" $(appdir)\temp\AdShower.exe "  active =" 0 "  parameter =" "  md5 =" dc411261f79fc8137164166f6f965641 " >
   < update  action =" 3 "  actionparam =" $(appdir)\temp "  cmd =" http://update.51cy.org:81/package/adshower.zip $(appdir)\update\package\adshower.zip " name =" update\package\adshower.zip "  />
   </ business >
   </ businesses >
   < files  />
   </ config >


从config.ini文件中读取businesses的值放到1.xml的businesses节点中

Element businesses = null;

Document docu = DocumentHelper.parseText(business); // 将字符串转为XML
 Element rootElt = docu.getRootElement(); // 获取根节点
if(root.element("businesses")==null){
businesses=root.addElement("businesses");
}
businesses.add(rootElt);

ServletContext sc = ServletActionContext.getServletContext();
String path = sc.getRealPath("1.xml");
OutputFormat format = OutputFormat.createPrettyPrint();
format.setEncoding("UTF-8");
FileOutputStream fos=new FileOutputStream(new File(path));
XMLWriter writer=new XMLWriter(fos,format);
writer.write(root);
writer.close();



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值