Home > Backend Development > XML/RSS Tutorial > Detailed explanation of conversion between xml and Java

Detailed explanation of conversion between xml and Java

Y2J
Release: 2017-05-10 10:06:59
Original
1870 people have browsed it

This article mainly introduces relevant information on the detailed explanation of the conversion of xml and Java objects. Friends in need can refer to the following

Detailed explanation of the conversion of xml and Java objects

1.xstream parsed message

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

2.xstream encapsulated message

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

3.Annotation:

@XStreamAlias("customerInfo")  //报文中<customerInfo>节点对应类名“PearTicketCustomerDTO”
public class PearTicketCustomerDTO {
@XStreamAlias("idno")   //报文中<idno>节点对应类属性“idno”
 private String idno;
@XStreamOmitField
private Long ticketId;  //报文中无<ticketId>节点 ,解析时忽略类属性ticketId
Copy after login

4. Method comparison

x.processAnnotations(new Class[]{PearTicketDTO.class}):读取类名注解
x.alias(new Class[]{PearTicketDTO.class}):不读取类名注解
Copy after login

5. Parse the message

x.alias("Equities", List.class);--把报文节点<Equities> 转化为List对象
x.alias("Equity", Equity.class);--把报文节点<Equity> 转化为Equity类对象
List<Equity> equities = (List<Equity>) x.fromXML(xml);--开始转化
Copy after login

[Related recommendations]

1. XML Free Video Tutorial

2. Li Yanhui XHTML Video Tutorial

3. XML Technical Manual

The above is the detailed content of Detailed explanation of conversion between xml and Java. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template