/** * 普通版填写包的公共部分 * @param root 开始节点 * @param map 参数map * @param sCycName 循环节点名 * @return */ public Element writeptPublicNode(Element root,HashMap map,String sCycName) { Element node=null; try { String sName=""; String sValue=""; List list=root.getChildren(); for(int i=0;i<list.size();i++) { node=(Element)list.get(i); sName=node.getName(); sName=sName.trim(); sValue=(String)map.get(sName); //System.err.println("sName:"+sName+":"+sValue); if(sCycName.equals(sName)&&(root.getName()).trim().equals("ReqParamSet")) { //System.err.println("find cyc node:"+sName ); return node; } else if(sValue!=null && !"".equals(sValue) ) node.setText(sValue); node=writeptPublicNode(node,map,sCycName); } }catch(Exception ex) { ex.printStackTrace(); System.err.println("error:"+ex.getMessage()); } return node; }
/** * * @param 普通版list 参数列表 */ public void writeptParaList(ArrayList list) { try { String sCaseName=""; String sItem=""; String sCycName=""; HashMap map=null; Document doc = builder.build(xmlFileName); Element root = doc.getRootElement(); Element element = root; Element cycNode=null; map=(HashMap)list.get(0); //参数文件map sItem="Description"; sCaseName=(String)map.get(sItem); mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP, "Description=" + sCaseName ); sItem="CysName"; sCycName=(String)map.get(sItem); map=(HashMap)list.get(1); //public 参数map cycNode=writeptPublicNode(element,map,sCycName); if( writeCycNode(cycNode,list)==false) //循环 参数 System.err.println(" write cyc node fail"); XMLOutputter outputter = new XMLOutputter("", false, "GB2312"); PrintWriter out = new PrintWriter(new BufferedWriter( new FileWriter(xmlFileName))); Document myDocument = root.getDocument(); outputter.output(myDocument, out); out.close(); } catch (JDOMException jdome) { jdome.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
/** * * @param map 需要写入的参数map * @param start 开始节点 * @param bNew 是否新增节点再写入参数 * @return */ public void writeParaMap(Element start,HashMap map) { try { String sName=""; String sValue=""; Element node=null; List list=start.getChildren(); for(int i=0;i<list.size();i++) { node=(Element)list.get(i); sName=node.getName(); sName=sName.trim(); sValue=(String)map.get(sName); if(sValue!=null && !"".equals(sValue) ); node.setText(sValue); } }catch(Exception ex) { ex.printStackTrace(); System.err.println("error:"+ex.getMessage()); } return ; }