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