zoukankan      html  css  js  c++  java
  • java解析xml

    public class XMLUtils {
        
        private static SAXReader reader = new SAXReader();
        private static Document dom = null;
        public static Document load(String fileName) {
            InputStream in = PropertiesHandler.class.getClassLoader()
            .getResourceAsStream("properties/" + fileName);
            try {
                dom = reader.read(in);
            } catch (DocumentException e) {
                e.printStackTrace();
            }
            return dom;
        }
        
        
        public static void main(String[] args) {
            Document dom = load("pushInfo.xml");
            String content = dom.getRootElement().element("sourceGoodsSMS").element("content").getText();
           String detail = MessageFormat.format(content,
                    "苹果",
                    "小五"
                    );
            System.out.println(detail);
            

        }


       properties/pushInfo.xml

        <?xml version="1.0" encoding="UTF-8"?

    >

    <!-- 推送货源给车辆时短信格式 -->
    <info>
    <sourceGoodsSMS>
        <content>
    飞驿网为您推送一条货源信息:货源名称:{0},联系人:{1};(详情请登录飞驿网http://www.56gate.com)
        </content>

    </sourceGoodsSMS>

    </info>

    打印:飞驿网为您推送一条货源信息:货源名称:苹果,联系人:小五;(详情请登录飞驿网http://www.56gate.com)

        

    }

  • 相关阅读:
    创建用户自定义函数 SQL
    sql with as 用法
    将string转为同名类名,方法名。(c#反射)
    linq 实现对象映射
    sql 游标
    C#编程总结(六)异步编程
    线程加锁解锁,用于循环条件不确定大小
    滚动条随代码滚动
    C# 代码小技巧
    reload方法
  • 原文地址:https://www.cnblogs.com/zhchoutai/p/7071743.html
Copyright © 2011-2022 走看看