Describes the an and XML conversion tools in detail.

Source: Internet
Author: User
This article describes the an and XML conversion tool classes in detail, which has some reference value. let's take a look at the jar packages using XStream.
X-stream.github.io/index.html
For the jar package, see the attachment.
XStream is a simple library to serialize objects to XML and back again.
Entity class

public class Person {  private String firstname; private String lastname; private PhoneNumber phone; private PhoneNumber fax;  public Person(String firstname,String lastname){ this.firstname = firstname;  this.lastname = lastname;  } public String getFirstname() {return firstname;}public void setFirstname(String firstname) {this.firstname = firstname;}public String getLastname() {return lastname;}public void setLastname(String lastname) {this.lastname = lastname;}public PhoneNumber getPhone() {return phone;}public void setPhone(PhoneNumber phone) {this.phone = phone;}public PhoneNumber getFax() {return fax;}public void setFax(PhoneNumber fax) {this.fax = fax;} }public class PhoneNumber {private int code;private String number;public PhoneNumber(int code,String number){this.code = code;this.number = number;}public int getCode() {return code;}public void setCode(int code) {this.code = code;}public String getNumber() {return number;}public void setNumber(String number) {this.number = number;}}

Tool

Import com. thoughtworks. xstream. XStream; import com. thoughtworks. xstream. io. xml. staxDriver; import com. wind. study. entity. person; import com. wind. study. entity. phoneNumber;/***** @ author wind * @ date 4:49:32, January 1, September 13, 2016 * @ Description: bean/XML conversion */public class BeanXMLConvertUtil {public static void main (String [] args) {XStream xstream = new XStream (new StaxDriver (); // XML output of XStream is more concise. you can create an alias for your custom class name X The name of the ML element. This is a unique type of ing that requires XStream or even optional. Xstream. alias ("person", Person. class); xstream. alias ("phonenumber", PhoneNumber. class); Person joe = new Person ("Joe", "Walnes"); joe. setPhone (new PhoneNumber (123, "1234-456"); joe. setFax (new PhoneNumber (123, "9999-999"); // bean to XMLString xml = xstream. toXML (joe); // XML to beanPerson newJoe = (Person) xstream. fromXML (xml); System. out. println (newJoe. getFirstname (); System. out. println (xml );}}

The above section details the an and XML tools. For more information, see other related articles in the first PHP community!

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.