首页 > 代码库 > java解析xml
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);
}
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)
}
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。