Java Parsing xml

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.