• Atitit xml xpath以及mybatis xml mapper脱机解析 目录 1.1. parseStt(String id, Element root) 1 1.2. parseStt


    Atitit xml xpath以及mybatis xml mapper脱机解析

     

     

    目录

    1.1. parseStt(String id, Element root) 1

    1.2. parseSttContestList(List li, Element root) 1

    1.3. ParseInclude(String refid, Element root) 2

     

     

     

    String xpath = "/update";

    // jdom

    SAXBuilder sb = new SAXBuilder();

    org.jdom.Document doc = sb.build(xmlf);

     

    Element root = (Element) doc.getRootElement();

     

     

      1.  parseStt(String id, Element root)

    private static String parseStt(String id, Element root) throws Exception {

    String pathFltById = "/mapper/*[@id='{0}']";

    // pathFltById = MessageFormat.format(pathFltById, id );

    pathFltById=pathFltById.replaceAll("\{0\}", id);

    Object sql = XPath.selectNodes(root, pathFltById);

    Element stt = (Element) XPath.selectSingleNode(root, pathFltById);

    List li = stt.getContent();

    // System.out.println();

    return parseSttContestList(li, root);

    }

      1. parseSttContestList(List li, Element root)

    private static String parseSttContestList(List li, Element root) throws Exception {

     

    List li_rzt = (List) li.stream().map(o -> {

    if (o instanceof Text) {

    return ((Text) o).getValue();

    }

    if (o instanceof Element) {

    Element o2 = (Element) o;

    if (o2.getName() == "include") {

    String refid = o2.getAttribute("refid").getValue();

    return ParseInclude(refid, root);

    }

    }

    //   return 0;

    return "";

     

    }).collect(Collectors.toList());

    return Joiner.on(" ").join(li_rzt);

    }

      1. ParseInclude(String refid, Element root) 

    private static Object ParseInclude(String refid, Element root) {

    try {

    // MessageFormat.format("我是{0},我来自{1}", "中国人", "中国");

    String pathFltById = "/mapper/sql[@id='{0}']/text()";

    pathFltById=pathFltById.replaceAll("\{0\}", refid);

    // pathFltById = MessageFormat.format(pathFltById, refid, "中国");

    //msg fomt cant use in xpath...bcz single quore is missed..

    Text sql;

     

    sql = (Text) XPath.selectSingleNode(root, pathFltById);

    return sql.getValue();

    } catch (JDOMException e) {

    // TODO Auto-generated catch block

    e.printStackTrace();

    throw new RuntimeException(e);

    }

     

    }

     

  • 相关阅读:
    CURL POST提交json类型字符串数据和伪造IP和来源
    windows下nginx的配置
    常用JS兼容问题工具
    无限级分类--Array写法
    JS获取对象指定属性在样式中的信息
    解决IE和Firefox获取来源网址Referer的JS方法
    异步轮询函数
    响应式布局--特殊设备检测
    jQuery Validate校验
    [LeetCode#124]Binary Tree Maximum Path Sum
  • 原文地址:https://www.cnblogs.com/attilax/p/15196943.html
Copyright © 2020-2023  润新知