dom4j修改xml文件

dom4j修改xml文件

@SuppressWarnings("unchecked")
	@Override
	public void insertCustomInfo(File file, String modelCode,List<Property> props) {
		SAXReader saxReadr = new SAXReader();// 得到SAXReader对象
		try {
			org.dom4j.Document  doc=saxReadr.read(file);
			org.dom4j.Element root = doc.getRootElement();// 得到根节点
			if (null != props && props.size() > 0) {
				//初始化删除添加的节点
				org.dom4j.Element styleElement = root.element("Styles");
				/*Iterator<org.dom4j.Element> it =styleElement.elementIterator();
				while(it.hasNext()) {
					org.dom4j.Element e = it.next();
			        if(e.)

			   }*/
				//List<org.dom4j.Element>  domList=styleElement.selectNodes("/.");
				//开始增加数据
				if (null != styleElement) {
					styleElement.addComment("custome style  start");
					for (Property p : props) {
						//FIXME 根据属性样式不同,添加不同的样式
						org.dom4j.Element se=styleElement.addElement("Style");
						se.addAttribute("ss:ID", p.getCode());
						se.addElement("NumberFormat");
						se.addElement("Protection");
					}
					styleElement.addComment("custome style  end");
				}
				org.dom4j.Element workSheetElement = root.element("Worksheet");
				if (null != workSheetElement) {
					org.dom4j.Element tableElement = workSheetElement.element("Table");
					if (null != tableElement) {
						org.dom4j.Element rowElement = tableElement.element("Row");
						if (null != rowElement) {
							for (Property p : props) {
								org.dom4j.Element cellEle=rowElement.addElement("Cell");
								cellEle.addElement("Data").addAttribute("ss:Type", "String").addText(InternationalResource.get(p.getDisplayName(), getCurrentLanguage()));
								org.dom4j.Element commentEle=cellEle.addElement("Comment").addAttribute("ss:Author", "");
								//commentEle.add(attribute);
							}
						}
						List<org.dom4j.Element> columnElements=tableElement.elements("Column");
						int size=columnElements.size();
						if(null!=columnElements&&columnElements.size()>0)  {
							org.dom4j.Element colE = tableElement.element("Column");
							if (null != colE) {
								for (Property p : props) {
									colE.addElement("Column").addAttribute("ss:Index", String.valueOf(size++));
									colE.addElement("Column").addAttribute("ss:Index", String.valueOf(size++));
								}
							}
						}
					}
				}

			}
			OutputFormat format = OutputFormat.createPrettyPrint();
			try {
				XMLWriter writer = new XMLWriter(new FileWriter(file), format);
				writer.write(doc);
				writer.flush();
				writer.close();
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
			log.info(root.getName());
		} catch (DocumentException e) {
			log.warn(e.getMessage());
		}
	       
	}

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/109113.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 文件读写api函数是什么_c语言文件的读和写

    文件读写api函数是什么_c语言文件的读和写文件操作API函数详解在VC中,大多数情况对文件的操作都使用系统提供的API函数,但有的函数我们不是很熟悉,以下提供一些文件操作API函数介绍:一般文件操作APICreateFile打开文件要对文件进行读写等操作,首先必须获得文件句柄,通过该函数可以获得文件句柄,该函数是通向文件世界的大门。ReadFile从文件中读取字节信息。在打开文件获得了文件句柄之后,则

    2025年7月22日
    0
  • MFCC算法讲解及实现(matlab)[通俗易懂]

    MFCC算法讲解及实现(matlab)[通俗易懂]史上最详细的MFCC算法实现(附测试数据)1.matlab安装voicebox语音包2.MFCC原理讲解3.MFCC算法设计实现(matlab)3.1.wav格式语音文件提取【x(200000*1)】3.2预加重【x(200000*1)】3.3分帧{S(301*1103)}3.4加窗{C(301*1103)}3.5傅里叶变换3.6梅尔滤波器3.7离散余弦变换4.1.matlab安装…

    2022年6月22日
    49
  • sql存储过程语法详解

    sql存储过程语法详解一、定义变量使用关键字declare申明变量:declare@变量名变量类型/*简单赋值*/declare@aintset@a=5print@a/*select赋值*/declare@bnvarchar(10)select@b=stu_namefromdbo.studentwherestu_id=6print@b/…

    2022年7月17日
    10
  • Win10下解决Wireshark“没有找到接口”的问题

    Win10下解决Wireshark“没有找到接口”的问题1 wireshark 自带的 Npcap 不支持 win10 需要重新下载 Win10Pcap 下载地址为 http www win10pcap org download 安装时需要关闭 wireshark 然后重新打开 wireshark 即可 2 把 wireshark 自带的 Npcap 程序卸载后 再次打开了 wireshark 程序 成功解决了

    2025年8月2日
    1
  • 关于使用iframe嵌套页面的跳转方式

    关于使用iframe嵌套页面的跳转方式一、背景A,B,C,D都是jsp,D是C的iframe,C是B的iframe,B是A的iframe,在D中跳转页面的写法区别如下。二、JS跳转window.location.href、location.href本页面跳转,D页面跳转parent.location.href上一层页面跳转,C页面跳转top.location.href最外层页面跳转,A页面跳转三、链接或者formD页面中有for…

    2022年6月16日
    53
  • Nessus漏洞扫描教程之配置Nessus

    Nessus漏洞扫描教程之配置Nessus

    2022年2月3日
    34

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号