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)

        

    }

  • 相关阅读:
    jquery练习(赋予属性值)
    jquery练习
    jquery表单对象属性选择器
    jquery表单选择器
    jquery子元素选择器
    jquery属性选择器(同时匹配多个条件)
    jquery属性选择器
    jquery属性选择器(匹配具有指定属性的元素)
    jquery可见性选择器(综合)
    方法的递归
  • 原文地址:https://www.cnblogs.com/zhchoutai/p/7071743.html
Copyright © 2011-2022 走看看