XML解析类

前端之家收集整理的这篇文章主要介绍了XML解析类前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
packagecom.duosen.gate.utils;
importjava.io.InputStream;
importjava.text.MessageFormat;
importjavax.xml.parsers.SAXParser;
importorg.dom4j.Document;
importorg.dom4j.DocumentException;
importorg.dom4j.Element;
importorg.dom4j.io.SAXReader;
importorg.jdom.input.SAXBuilder;
/**
*@项目名称:56gate
*@类名称:XMLUtils
*@类描述
*@创建人liliang
*@创建时间:2013-10-12下午05:03:31
*@修改liliang
*@修改时间:2013-10-12下午05:03:31
*@修改备注
*@version1.0
*/
publicclassXMLUtils{
privatestaticSAXReaderreader=newSAXReader();
privatestaticDocumentdom=null;
publicstaticDocumentload(StringfileName){
InputStreamin=PropertiesHandler.class.getClassLoader()
.getResourceAsStream(PropertiesHandler.PROP_DIR+fileName);
try{
dom=reader.read(in);
}catch(DocumentExceptione){
e.printStackTrace();
}
returndom;
}
publicstaticvoidmain(String[]args){
Documentdom=load("pushInfo.xml");
Stringcontent=dom.getRootElement().element("sourceGoodsSMS").element("content").getText();
Stringdetail=MessageFormat.format(content,
"goodsname",
"contact",
"phone",
"address",
"bulk",
"weight",
"shipping",
"startTime",
"fromCityName"+"-"+"toCityName"
);
System.out.println(detail);
}
}
原文链接:https://www.f2er.com/xml/297560.html

猜你在找的XML相关文章