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,
"Apple",
"Small Five"
);
SYSTEM.OUT.PRINTLN (detail);
}
Properties/pushinfo.xml
<?xml version= "1.0" encoding= "UTF-8"?
>
<!--push the source to the vehicle when SMS format--
<info>
<sourceGoodsSMS>
<content>
Flight network for you to push a source of information: Source name: {0}, contact: {1};(details, please log in to the network http://www.56gate.com)
</content>
</sourceGoodsSMS>
</info>
Printing: The flight network for you to push a source of information: Source Name: Apple, contact: small five; (for details, please login to http://www.56gate.com)
}
Java Parsing xml