设为首页 加入收藏

TOP

clob保存为本地xml文件,修改后上传(三)
2015-07-24 10:24:02 来源: 作者: 【 】 浏览:2
Tags:clob 保存 本地 xml 文件 修改 上传
public void insertElementNode(String fileName, String nodeName, String newElementName) { document = parserXml(fileName); NodeList nodeList = document.getElementsByTagName(nodeName); for (int i = 0; i < nodeList.getLength(); i++) { Element element = document.createElement(newElementName); nodeList.item(i).appendChild(element); } createXml(fileName); } public void insertAttrNode(String fileName, String nodeName, String newAttrName, String attrValue) { document = parserXml(fileName); NodeList nodeList = document.getElementsByTagName(nodeName); for (int i = 0; i < nodeList.getLength(); i++) { Element element = (Element) (nodeList.item(i)); element.setAttribute(newAttrName, attrValue); } createXml(fileName); } public void insertTextNode(String fileName, String nodeName, String textNode) { document = parserXml(fileName); NodeList nodeList = document.getElementsByTagName(nodeName); for (int i = 0; i < nodeList.getLength(); i++) { nodeList.item(i).appendChild(document.createTextNode(textNode)); } createXml(fileName); } public void deleteElementNode(String fileName, String nodeName) { document = parserXml(fileName); NodeList nodeList = document.getElementsByTagName(nodeName); while (nodeList.getLength() > 0) { nodeList.item(0).getParentNode().removeChild(nodeList.item(0)); nodeList = document.getElementsByTagName(nodeName); } createXml(fileName); } public void updateNode(String fileName, String nodeName, String attrName, String newAttrValue) { document = parserXml(fileName); NodeList nodeList = document.getElementsByTagName(nodeName); for (int i = 0; i < nodeList.getLength(); i++) { Element node = (Element) nodeList.item(i); node.setAttribute(attrName, newAttrValue); } createXml(fileName); } private Document parserXml(String fileName) { try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document document = db.parse(fileName); System.out.println("-----------------------------------" + "解析完毕" + "----------------------------------------"); return document; } catch (FileNotFoundException e) { System.out.println(e.getMessage()); } catch (ParserConfigurationException e) { System.out.println(e.getMessage()); } catch (SAXException e) { System.out.println(e.getMessage()); } catch (IOException e) { System.out.println(e.getMessage()); } return document; } private void createXml(String fileName) { try { /** 将document中的内容写入文件中 */ TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); DOMSource source = new DOMSource(document); StreamResult result = new StreamResult(new FileOutputStream( fileName)); transformer.transform(source, result); System.out.println("--------------------------------" + "更新 XML文件成功" + "-------------------------------------"); } catch (Exception exception) { System.out.println("更新" + fileName + "出错:" + exception); exception.printStackTrace(); } } }
最后程序提供的接口与说明如下

?

?

/**
 * @author GuoDi and ZhangWen
 *
 */
public interface NodeInfoInterface {
    
    /** 
    * XML文档 插元素入节点
    * @param time 时间
    * @param nodeName 标签名
    * @param newElementName 新标签
    */ 
    public void insertElementNode(String time, String nodeName,String newElementName);
	
    /** 
    * @param time 时间
    * @param nodeName 标签名
    * @param newAttrName 新属性名
    * @param attrValue 新属性值
    * XML文档 插入属性节点
    */ 
    public void insertAttrNode(String time,String nodeName,String newAttrName,String attrValue);
	
    /** 
    * @param time 时间
    * @param nodeName 标签名
    * @param textNode 文本
    * XML文档 插入文本节点
    */ 
    public void insertTextNode(String time,String nodeName,String textNode);
	
    /** 
    * @param time 时间
    * @param nodeName 标签名
    * XML文档 删除所有对应元素节点
    */ 
    public void deleteElementNode(String time,String nodeName);
	
    /** 
    * @param time 时间
    * @param nodeName 标签名
    * @param newAttrName 新属性名
    * @param attrValue 新属性值
    * XML文档 修改属性节点内容
    */ 
    public void updateNode(String time,String nodeName,String newAttrName,String attrValue);
	
}


?

首页 上一页 1 2 3 下一页 尾页 3/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇数据块内部偏移量的基本计算方法 下一篇sumover用法,以及与groupby的区别

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·C 内存管理 | 菜鸟教 (2025-12-26 20:20:37)
·如何在 C 语言函数中 (2025-12-26 20:20:34)
·国际音标 [ç] (2025-12-26 20:20:31)
·微服务 Spring Boot (2025-12-26 18:20:10)
·如何调整 Redis 内存 (2025-12-26 18:20:07)