Explanation of the conversion between xml and Java

Source: Internet
Author: User
This article mainly introduces detailed information about the conversion between xml and Java objects. For more information about the conversion between xml and Java objects, see the next article, for more information, see

Conversion between xml and Java objects

1. xstream resolution packets

XStreamComponent x = XStreamComponent.newInstance(); x.processAnnotations(new Class[]{EquityExchangeDetail.class,PearTicketCustomerDTO.class,Date.class,Integer.class}); EquityExchangeDetail ptd = (EquityExchangeDetail) x.fromXML(xml);

2. xstream encapsulation packets

XStreamComponent xres = XStreamComponent.newInstance();    xres.processAnnotations(new Class[]{TransResult.class}); String result=xres.toXML(transResult);

3. Annotation:

@ XStreamAlias ("customerInfo") // message
 
  
The corresponding class name of the node is "PearTicketCustomerDTO" public class PearTicketCustomerDTO {@ XStreamAlias ("idno") // message
  
   
The class attribute "idno" private String idno corresponding to the node; @ XStreamOmitFieldprivate Long ticketId; // none in the message
   
    
Node. the class attribute ticketId is ignored during parsing.
   
  
 

4. method comparison

X. processAnnotations (new Class [] {PearTicketDTO. class}): Read Class name annotation x. alias (new class [] {PearTicketDTO. Class}): Do not read class name annotation

5. parse packets

X. alias ("Equities", List. class); -- sets the packet node
 
  
Convert to List object x. alias ("Equity", Equity. class); -- converts the packet node
  
   
Convert to Equity class object List
   
    
Equities = (List
    
     
) X. fromXML (xml); -- start conversion
    
   
  
 

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.