zoukankan      html  css  js  c++  java
  • Xapth 添加注释头

    private static void updateMybatisXml(String url, String username, String password) {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setIgnoringElementContentWhitespace(false);
    try {
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document xmldoc = db.parse(xmlPath);

    Element root = xmldoc.getDocumentElement();
    Element per = (Element) selectSingleNode("/configuration/environments/environment/dataSource", root);
    NodeList properties = per.getElementsByTagName("property");

    Element urlElement = (Element) properties.item(1);
    urlElement.setAttribute("value", url);
    Element userNameElement = (Element) properties.item(2);
    userNameElement.setAttribute("value", username);
    Element passwordElement = (Element) properties.item(3);
    passwordElement.setAttribute("value", password);

    TransformerFactory factory = TransformerFactory.newInstance();
    Transformer transformer = factory.newTransformer();
    DOMImplementation domImpl = xmldoc.getImplementation();
    DocumentType doctype = domImpl.createDocumentType("configuration",
    "-//mybatis.org//DTD Config 3.0//EN",
    "http://mybatis.org/dtd/mybatis-3-config.dtd");
    transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, doctype.getPublicId());
    transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, doctype.getSystemId());
    transformer.transform(new DOMSource(xmldoc), new StreamResult(new File(xmlPath)));
    } catch (Exception e) {
    System.out.println(e.getMessage());
    }
    }

    public static Node selectSingleNode(String express, Element source) {
    Node result = null;
    XPathFactory xpathFactory = XPathFactory.newInstance();
    XPath xpath = xpathFactory.newXPath();
    try {
    result = (Node) xpath.evaluate(express, source, XPathConstants.NODE);
    System.out.println(result);
    } catch (XPathExpressionException e) {
    System.out.println(e.getMessage());
    }

    return result;
    }
  • 相关阅读:
    游戏AI系列内容 咋样才能做个有意思的AI呢
    图片缩放的相关处理
    Lua 安全调用 metatable 的简单应用
    让Lua自己把文件夹下面的所有文件自动加载起来吧
    【原创】有利于提高xenomai 实时性的一些配置建议
    环境篇:Docker
    环境篇:Virtualbox+Vagrant安装Centos7
    环境篇:VMware Workstation安装Centos7
    软件篇:前端保姆->VSCode
    大数据篇:ElasticSearch
  • 原文地址:https://www.cnblogs.com/wuwei928/p/8521096.html
Copyright © 2011-2022 走看看