Xml 转实体类对象

Xml 转实体类对象

步骤:

1. 读取Xml 数据转换成一个json数据;

2. 把json数据转成实体类对象;

maven依赖:

<dependency>
	<groupId>dom4j</groupId>
	<artifactId>dom4j</artifactId>
	<version>1.6.1</version>
</dependency>
<dependency>
	<groupId>commons-io</groupId>
	<artifactId>commons-io</artifactId>
	<version>2.6</version>
</dependency>
<dependency>
	<groupId>com.alibaba</groupId>
	<artifactId>fastjson</artifactId>
	<version>1.2.23</version>
</dependency>

工具类:

package com.liantuo.international.utils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.liantuo.international.domain.Response;
import org.dom4j.*;
import java.util.List;
import static org.springframework.util.StringUtils.isEmpty;


/**
 * @author
 * @Description
 * @date 2019/8/20
 */
public class Xml2JsonUtil {

    /**
     * xml转json
     * @param element
     * @param json
     */
    public static void dom4j2Json(Element element,JSONObject json){
        //如果是属性
        for(Object o:element.attributes()){
            Attribute attr=(Attribute)o;
            if(!isEmpty(attr.getValue())){
                json.put("@"+attr.getName(), attr.getValue());
            }
        }
        List<Element> chdEl=element.elements();
        //如果没有子元素,只有一个值
        if(chdEl.isEmpty()&&!isEmpty(element.getText())){
            json.put(element.getName(), element.getText());
        }

        //有子元素
        for(Element e:chdEl){
            //子元素也有子元素
            if(!e.elements().isEmpty()){
                JSONObject chdjson=new JSONObject();
                dom4j2Json(e,chdjson);
                Object o=json.get(e.getName());
                if(o!=null){
                    JSONArray jsona=null;
                    //如果此元素已存在,则转为jsonArray
                    if(o instanceof JSONObject){
                        JSONObject jsono=(JSONObject)o;
                        json.remove(e.getName());
                        jsona=new JSONArray();
                        jsona.add(jsono);
                        jsona.add(chdjson);
                    }
                    if(o instanceof JSONArray){
                        jsona=(JSONArray)o;
                        jsona.add(chdjson);
                    }
                    json.put(e.getName(), jsona);
                }else{
                    if(!chdjson.isEmpty()){
                        json.put(e.getName(), chdjson);
                    }
                }


            }else{
                //子元素没有子元素
                for(Object o:element.attributes()){
                    Attribute attr=(Attribute)o;
                    if(!isEmpty(attr.getValue())){
                        json.put("@"+attr.getName(), attr.getValue());
                    }
                }
                if(!e.getText().isEmpty()){
                    json.put(e.getName(), e.getText());
                }
            }
        }
    }

 }

实体类:

H3ads实体类:

package com.liantuo.international.domain;


/**
 * @author lidada
 * @Description
 * @date 2019/8/20
 */


public class H3ads {
    private String h3ad;


    public H3ads() {
    }

    public H3ads(String h3ad) {
        this.h3ad = h3ad;
    }

    public void setH3ad(String h3ad) {
        this.h3ad = h3ad;
    }
    public String getH3ad() {
        return h3ad;
    }

}

OTA_AVE_RS实体类:

package com.liantuo.international.domain;


/**
 * @author lidada
 * @Description
 * @date 2019/8/20
 */

public class OTA_AVE_RS {

    private Response Response;

    public Response getResponse() {
        return Response;
    }

    public void setResponse(Response response) {
        Response = response;
    }
}

Out1实体类:

package com.liantuo.international.domain;

import com.alibaba.fastjson.annotation.JSONField;

/**
 * @author lidada
 * @Description
 * @date 2019/8/20
 */

public class Out1 {

    @JSONField(format = "yyyy-MM-dd")
    private String dt;
    private String week;
    private String dep;
    private String arr;
    private String depcity;
    private String arrcity;
    private String filter;
    private Segs segs;
    private H3ads h3ads;

    public Out1() {
    }

    public Out1(String dt, String week, String dep, String arr, String depcity, String arrcity, String filter, Segs segs, H3ads h3ads) {
        this.dt = dt;
        this.week = week;
        this.dep = dep;
        this.arr = arr;
        this.depcity = depcity;
        this.arrcity = arrcity;
        this.filter = filter;
        this.segs = segs;
        this.h3ads = h3ads;
    }

    public String getDt() {
        return dt;
    }

    public void setDt(String dt) {
        this.dt = dt;
    }

    public String getWeek() {
        return week;
    }

    public void setWeek(String week) {
        this.week = week;
    }

    public String getDep() {
        return dep;
    }

    public void setDep(String dep) {
        this.dep = dep;
    }

    public String getArr() {
        return arr;
    }

    public void setArr(String arr) {
        this.arr = arr;
    }

    public String getDepcity() {
        return depcity;
    }

    public void setDepcity(String depcity) {
        this.depcity = depcity;
    }

    public String getArrcity() {
        return arrcity;
    }

    public void setArrcity(String arrcity) {
        this.arrcity = arrcity;
    }

    public String getFilter() {
        return filter;
    }

    public void setFilter(String filter) {
        this.filter = filter;
    }

    public Segs getSegs() {
        return segs;
    }

    public void setSegs(Segs segs) {
        this.segs = segs;
    }

    public H3ads getH3ads() {
        return h3ads;
    }

    public void setH3ads(H3ads h3ads) {
        this.h3ads = h3ads;
    }
}

Response实体类:

package com.liantuo.international.domain;



/**
 * @author lidada
 * @Description
 * @date 2019/8/20
 */

public class Response {

    private String ID;
    private String StName;
    private String SN;
    private String Flag;
    private Out1 out1;
    public Response() {
    }

    public Response(String ID, String stName, String SN, String flag, Out1 out1) {
        this.ID = ID;
        StName = stName;
        this.SN = SN;
        Flag = flag;
        this.out1 = out1;
    }

    public String getID() {
        return ID;
    }

    public void setID(String ID) {
        this.ID = ID;
    }

    public String getStName() {
        return StName;
    }

    public void setStName(String stName) {
        StName = stName;
    }

    public String getSN() {
        return SN;
    }

    public void setSN(String SN) {
        this.SN = SN;
    }

    public String getFlag() {
        return Flag;
    }

    public void setFlag(String flag) {
        Flag = flag;
    }

    public Out1 getOut1() {
        return out1;
    }

    public void setOut1(Out1 out1) {
        this.out1 = out1;
    }
}

SeatAndNum实体类:

package com.liantuo.international.domain;

/**
 * @author lidada
 * @Description
 * @date 2019/8/20
 */
public class SeatAndNum {


    private String name;
    private String av;

    public SeatAndNum() {
    }

    public SeatAndNum(String name, String av) {
        this.name = name;
        this.av = av;
    }

    public void setName(String name) {
        this.name = name;
    }
    public String getName() {
        return name;
    }

    public void setAv(String av) {
        this.av = av;
    }
    public String getAv() {
        return av;
    }

}

SeatAndNums实体类:

package com.liantuo.international.domain;


import java.util.List;

/**
 * @author lidada
 * @Description
 * @date 2019/8/20
 */
public class SeatAndNums {


    private List<SeatAndNum> seatAndNum;


    public SeatAndNums() {
    }

    public SeatAndNums(List<SeatAndNum> seatAndNum) {
        this.seatAndNum = seatAndNum;
    }

    public List<SeatAndNum> getSeatAndNum() {
        return seatAndNum;
    }

    public void setSeatAndNum(List<SeatAndNum> seatAndNum) {
        this.seatAndNum = seatAndNum;
    }
}

Seg实体类:

package com.liantuo.international.domain;

import javax.xml.bind.annotation.XmlRootElement;
import java.util.Date;

/**
 * @author lidada
 * @Description
 * @date 2019/8/20
 */

public class Seg {
    private String routno;
    private String subid;
    private String airline;
    private String fltno;
    private String dep;
    private String arr;
    private String dt;
    private String week;
    private String deptm;
    private String arrtm;
    private String dev;
    private String stop;
    private String ASR;
    private String meal;
    private String et;
    private String lnk;
    private Term term;
    private String flytm;
    private String journeytm;
    private SeatAndNums seatAndNums;

    public Seg() {
    }

    public Seg(String routno, String subid, String airline, String fltno, String dep, String arr, String dt, String week, String deptm, String arrtm, String dev, String stop, String ASR, String meal, String et, String lnk, Term term, String flytm, String journeytm, SeatAndNums seatAndNums) {
        this.routno = routno;
        this.subid = subid;
        this.airline = airline;
        this.fltno = fltno;
        this.dep = dep;
        this.arr = arr;
        this.dt = dt;
        this.week = week;
        this.deptm = deptm;
        this.arrtm = arrtm;
        this.dev = dev;
        this.stop = stop;
        this.ASR = ASR;
        this.meal = meal;
        this.et = et;
        this.lnk = lnk;
        this.term = term;
        this.flytm = flytm;
        this.journeytm = journeytm;
        this.seatAndNums = seatAndNums;
    }

    public String getRoutno() {
        return routno;
    }

    public void setRoutno(String routno) {
        this.routno = routno;
    }

    public String getSubid() {
        return subid;
    }

    public void setSubid(String subid) {
        this.subid = subid;
    }

    public String getAirline() {
        return airline;
    }

    public void setAirline(String airline) {
        this.airline = airline;
    }

    public String getFltno() {
        return fltno;
    }

    public void setFltno(String fltno) {
        this.fltno = fltno;
    }

    public String getDep() {
        return dep;
    }

    public void setDep(String dep) {
        this.dep = dep;
    }

    public String getArr() {
        return arr;
    }

    public void setArr(String arr) {
        this.arr = arr;
    }

    public String getDt() {
        return dt;
    }

    public void setDt(String dt) {
        this.dt = dt;
    }

    public String getWeek() {
        return week;
    }

    public void setWeek(String week) {
        this.week = week;
    }

    public String getDeptm() {
        return deptm;
    }

    public void setDeptm(String deptm) {
        this.deptm = deptm;
    }

    public String getArrtm() {
        return arrtm;
    }

    public void setArrtm(String arrtm) {
        this.arrtm = arrtm;
    }

    public String getDev() {
        return dev;
    }

    public void setDev(String dev) {
        this.dev = dev;
    }

    public String getStop() {
        return stop;
    }

    public void setStop(String stop) {
        this.stop = stop;
    }

    public String getASR() {
        return ASR;
    }

    public void setASR(String ASR) {
        this.ASR = ASR;
    }

    public String getMeal() {
        return meal;
    }

    public void setMeal(String meal) {
        this.meal = meal;
    }

    public String getEt() {
        return et;
    }

    public void setEt(String et) {
        this.et = et;
    }

    public String getLnk() {
        return lnk;
    }

    public void setLnk(String lnk) {
        this.lnk = lnk;
    }

    public Term getTerm() {
        return term;
    }

    public void setTerm(Term term) {
        this.term = term;
    }

    public String getFlytm() {
        return flytm;
    }

    public void setFlytm(String flytm) {
        this.flytm = flytm;
    }

    public String getJourneytm() {
        return journeytm;
    }

    public void setJourneytm(String journeytm) {
        this.journeytm = journeytm;
    }

    public SeatAndNums getSeatAndNums() {
        return seatAndNums;
    }

    public void setSeatAndNums(SeatAndNums seatAndNums) {
        this.seatAndNums = seatAndNums;
    }
}

Segs实体类:

package com.liantuo.international.domain;

import javax.xml.bind.annotation.XmlRootElement;
import java.util.List;

/**
 * @author lidada
 * @Description
 * @date 2019/8/20
 */

public class Segs {


    private List<Seg> seg;

    public Segs() {
    }

    public Segs(List<Seg> seg) {
        this.seg = seg;
    }

    public void setSeg(List<Seg> seg) {
        this.seg = seg;
    }
    public List<Seg> getSeg() {
        return seg;
    }
}

Term实体类:

package com.liantuo.international.domain;


/**
 * @author lidada
 * @Description
 * @date 2019/8/20
 */

    public class Term {

        private String dep;
        private String arr;

    public Term(String dep, String arr) {
        this.dep = dep;
        this.arr = arr;
    }

    public Term() {
    }

    public void setDep(String dep) {
            this.dep = dep;
        }
        public String getDep() {
            return dep;
        }

        public void setArr(String arr) {
            this.arr = arr;
        }
        public String getArr() {
            return arr;
        }

    }


测试:

package com.liantuo.international.utils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.liantuo.international.domain.Response;
import org.dom4j.*;
import java.util.List;

import static org.springframework.util.StringUtils.isEmpty;


/**
 * @author
 * @Description
 * @date 2019/8/20
 */
public class Xml2JsonDemo {


    public static void main(String[] args) throws DocumentException {
        String x = "<OTA_AVE_RS><Response><ID>C297818</ID><StName>AV</StName><SN>0</SN><Flag>S</Flag><out1><dt>10OCT19</dt><week>THU</week><dep>BJS</dep><arr>SHA</arr><depcity>BJS</depcity><arrcity>SHA</arrcity><filter>VIA MU DIRECT ONLY Y</filter><segs><seg><routno>1</routno><subid>1</subid><airline>MU</airline><fltno>5138</fltno><dep>PEK</dep><arr>SHA</arr><dt>10OCT19</dt><week>THU</week><deptm>0700</deptm><arrtm>0920</arrtm><dev>33L</dev><stop>0</stop><ASR>^</ASR><meal>B</meal><et>E</et><lnk>DS#</lnk><term><dep>T2</dep><arr>T2</arr></term><flytm>2:20</flytm><journeytm>2:20</journeytm><seatAndNums><seatAndNum><name>J</name><av>A</av></seatAndNum><seatAndNum><name>C</name><av>A</av></seatAndNum><seatAndNum><name>D</name><av>A</av></seatAndNum><seatAndNum><name>Q</name><av>A</av></seatAndNum><seatAndNum><name>I</name><av>A</av></seatAndNum><seatAndNum><name>W</name><av>A</av></seatAndNum><seatAndNum><name>Y</name><av>A</av></seatAndNum><seatAndNum><name>B</name><av>A</av></seatAndNum><seatAndNum><name>M</name><av>A</av></seatAndNum><seatAndNum><name>E</name><av>A</av></seatAndNum><seatAndNum><name>H</name><av>A</av></seatAndNum><seatAndNum><name>K</name><av>A</av></seatAndNum><seatAndNum><name>L</name><av>A</av></seatAndNum><seatAndNum><name>N</name><av>A</av></seatAndNum><seatAndNum><name>R</name><av>A</av></seatAndNum></seatAndNums><sav><as><service_type>INFT</service_type><control_level>FLIGHT</control_level><service_status><status>OPEN</status><av_num>15</av_num></service_status></as></sav></seg><seg><routno>2</routno><subid>1</subid><airline>MU</airline><fltno>5183</fltno><dep>PEK</dep><arr>PVG</arr><dt>10OCT19</dt><week>THU</week><deptm>0735</deptm><arrtm>0950</arrtm><dev>321</dev><stop>0</stop><ASR>^</ASR><meal>S</meal><et>E</et><lnk>DS#</lnk><term><dep>T2</dep><arr>T1</arr></term><flytm>2:15</flytm><journeytm>2:15</journeytm><seatAndNums><seatAndNum><name>J</name><av>A</av></seatAndNum><seatAndNum><name>Y</name><av>A</av></seatAndNum><seatAndNum><name>B</name><av>A</av></seatAndNum><seatAndNum><name>M</name><av>A</av></seatAndNum><seatAndNum><name>E</name><av>A</av></seatAndNum><seatAndNum><name>H</name><av>A</av></seatAndNum><seatAndNum><name>K</name><av>A</av></seatAndNum><seatAndNum><name>L</name><av>A</av></seatAndNum><seatAndNum><name>N</name><av>A</av></seatAndNum><seatAndNum><name>R</name><av>A</av></seatAndNum></seatAndNums><sav><as><service_type>INFT</service_type><control_level>FLIGHT</control_level><service_status><status>OPEN</status><av_num>8</av_num></service_status></as></sav></seg><seg><routno>3</routno><subid>1</subid><airline>MU</airline><fltno>5102</fltno><dep>PEK</dep><arr>SHA</arr><dt>10OCT19</dt><week>THU</week><deptm>0800</deptm><arrtm>1015</arrtm><dev>333</dev><stop>0</stop><ASR>^</ASR><meal>S</meal><et>E</et><lnk>DS#</lnk><term><dep>T2</dep><arr>T2</arr></term><flytm>2:15</flytm><journeytm>2:15</journeytm><seatAndNums><seatAndNum><name>J</name><av>A</av></seatAndNum><seatAndNum><name>C</name><av>A</av></seatAndNum><seatAndNum><name>D</name><av>A</av></seatAndNum><seatAndNum><name>Q</name><av>A</av></seatAndNum><seatAndNum><name>I</name><av>A</av></seatAndNum><seatAndNum><name>Y</name><av>A</av></seatAndNum><seatAndNum><name>B</name><av>A</av></seatAndNum><seatAndNum><name>M</name><av>A</av></seatAndNum><seatAndNum><name>E</name><av>A</av></seatAndNum><seatAndNum><name>H</name><av>A</av></seatAndNum><seatAndNum><name>K</name><av>A</av></seatAndNum><seatAndNum><name>L</name><av>A</av></seatAndNum><seatAndNum><name>N</name><av>A</av></seatAndNum><seatAndNum><name>R</name><av>A</av></seatAndNum></seatAndNums><sav><as><service_type>INFT</service_type><control_level>FLIGHT</control_level><service_status><status>OPEN</status><av_num>15</av_num></service_status></as></sav></seg><seg><routno>4</routno><subid>1</subid><airline>MU</airline><fltno>5156</fltno><dep>PEK</dep><arr>SHA</arr><dt>10OCT19</dt><week>THU</week><deptm>0830</deptm><arrtm>1040</arrtm><dev>33L</dev><stop>0</stop><ASR>^</ASR><meal>S</meal><et>E</et><lnk>DS#</lnk><term><dep>T2</dep><arr>T2</arr></term><flytm>2:10</flytm><journeytm>2:10</journeytm><seatAndNums><seatAndNum><name>J</name><av>A</av></seatAndNum><seatAndNum><name>C</name><av>A</av></seatAndNum><seatAndNum><name>D</name><av>A</av></seatAndNum><seatAndNum><name>Q</name><av>A</av></seatAndNum><seatAndNum><name>I</name><av>A</av></seatAndNum><seatAndNum><name>W</name><av>A</av></seatAndNum><seatAndNum><name>Y</name><av>A</av></seatAndNum><seatAndNum><name>B</name><av>A</av></seatAndNum><seatAndNum><name>M</name><av>A</av></seatAndNum><seatAndNum><name>E</name><av>A</av></seatAndNum><seatAndNum><name>H</name><av>A</av></seatAndNum><seatAndNum><name>K</name><av>A</av></seatAndNum><seatAndNum><name>L</name><av>A</av></seatAndNum><seatAndNum><name>N</name><av>A</av></seatAndNum><seatAndNum><name>R</name><av>A</av></seatAndNum></seatAndNums><sav><as><service_type>INFT</service_type><control_level>FLIGHT</control_level><service_status><status>OPEN</status><av_num>15</av_num></service_status></as></sav></seg><seg><routno>5</routno><subid>1</subid><airline>MU</airline><fltno>5104</fltno><dep>PEK</dep><arr>SHA</arr><dt>10OCT19</dt><week>THU</week><deptm>0900</deptm><arrtm>1115</arrtm><dev>33L</dev><stop>0</stop><ASR>^</ASR><meal>S</meal><et>E</et><lnk>DS#</lnk><term><dep>T2</dep><arr>T2</arr></term><flytm>2:15</flytm><journeytm>2:15</journeytm><seatAndNums><seatAndNum><name>J</name><av>A</av></seatAndNum><seatAndNum><name>C</name><av>A</av></seatAndNum><seatAndNum><name>D</name><av>A</av></seatAndNum><seatAndNum><name>W</name><av>A</av></seatAndNum><seatAndNum><name>Y</name><av>A</av></seatAndNum><seatAndNum><name>B</name><av>A</av></seatAndNum><seatAndNum><name>M</name><av>A</av></seatAndNum><seatAndNum><name>E</name><av>A</av></seatAndNum><seatAndNum><name>H</name><av>A</av></seatAndNum><seatAndNum><name>K</name><av>A</av></seatAndNum><seatAndNum><name>L</name><av>A</av></seatAndNum><seatAndNum><name>N</name><av>A</av></seatAndNum><seatAndNum><name>R</name><av>A</av></seatAndNum></seatAndNums><sav><as><service_type>INFT</service_type><control_level>FLIGHT</control_level><service_status><status>OPEN</status><av_num>15</av_num></service_status></as></sav></seg><seg><routno>6</routno><subid>1</subid><airline>MU</airline><fltno>5106</fltno><dep>PEK</dep><arr>SHA</arr><dt>10OCT19</dt><week>THU</week><deptm>1000</deptm><arrtm>1215</arrtm><dev>33L</dev><stop>0</stop><ASR>^</ASR><meal>S</meal><et>E</et><lnk>DS#</lnk><term><dep>T2</dep><arr>T2</arr></term><flytm>2:15</flytm><journeytm>2:15</journeytm><seatAndNums><seatAndNum><name>J</name><av>A</av></seatAndNum><seatAndNum><name>C</name><av>A</av></seatAndNum><seatAndNum><name>D</name><av>A</av></seatAndNum><seatAndNum><name>W</name><av>A</av></seatAndNum><seatAndNum><name>Y</name><av>A</av></seatAndNum><seatAndNum><name>B</name><av>A</av></seatAndNum><seatAndNum><name>M</name><av>A</av></seatAndNum><seatAndNum><name>E</name><av>A</av></seatAndNum><seatAndNum><name>H</name><av>A</av></seatAndNum><seatAndNum><name>K</name><av>A</av></seatAndNum><seatAndNum><name>L</name><av>A</av></seatAndNum><seatAndNum><name>N</name><av>A</av></seatAndNum><seatAndNum><name>R</name><av>A</av></seatAndNum></seatAndNums><sav><as><service_type>INFT</service_type><control_level>FLIGHT</control_level><service_status><status>OPEN</status><av_num>15</av_num></service_status></as></sav></seg><seg><routno>7</routno><subid>1</subid><airline>MU</airline><fltno>5108</fltno><dep>PEK</dep><arr>SHA</arr><dt>10OCT19</dt><week>THU</week><deptm>1100</deptm><arrtm>1320</arrtm><dev>33L</dev><stop>0</stop><ASR>^</ASR><meal>D</meal><et>E</et><lnk>DS#</lnk><term><dep>T2</dep><arr>T2</arr></term><flytm>2:20</flytm><journeytm>2:20</journeytm><seatAndNums><seatAndNum><name>J</name><av>A</av></seatAndNum><seatAndNum><name>W</name><av>A</av></seatAndNum><seatAndNum><name>Y</name><av>A</av></seatAndNum><seatAndNum><name>B</name><av>A</av></seatAndNum><seatAndNum><name>M</name><av>A</av></seatAndNum><seatAndNum><name>E</name><av>A</av></seatAndNum><seatAndNum><name>H</name><av>A</av></seatAndNum><seatAndNum><name>K</name><av>A</av></seatAndNum><seatAndNum><name>L</name><av>A</av></seatAndNum><seatAndNum><name>N</name><av>A</av></seatAndNum><seatAndNum><name>R</name><av>A</av></seatAndNum></seatAndNums><sav><as><service_type>INFT</service_type><control_level>FLIGHT</control_level><service_status><status>OPEN</status><av_num>15</av_num></service_status></as></sav></seg><seg><routno>8</routno><subid>1</subid><airline>MU</airline><fltno>5152</fltno><dep>PEK</dep><arr>SHA</arr><dt>10OCT19</dt><week>THU</week><deptm>1130</deptm><arrtm>1400</arrtm><dev>32L</dev><stop>0</stop><ASR>^</ASR><meal>D</meal><et>E</et><lnk>DS#</lnk><term><dep>T2</dep><arr>T2</arr></term><flytm>2:30</flytm><journeytm>2:30</journeytm><seatAndNums><seatAndNum><name>J</name><av>A</av></seatAndNum><seatAndNum><name>W</name><av>A</av></seatAndNum><seatAndNum><name>Y</name><av>A</av></seatAndNum><seatAndNum><name>B</name><av>A</av></seatAndNum><seatAndNum><name>M</name><av>A</av></seatAndNum><seatAndNum><name>E</name><av>A</av></seatAndNum><seatAndNum><name>H</name><av>A</av></seatAndNum><seatAndNum><name>K</name><av>A</av></seatAndNum><seatAndNum><name>L</name><av>A</av></seatAndNum><seatAndNum><name>N</name><av>A</av></seatAndNum><seatAndNum><name>R</name><av>A</av></seatAndNum></seatAndNums><sav><as><service_type>INFT</service_type><control_level>FLIGHT</control_level><service_status><status>OPEN</status><av_num>6</av_num></service_status></as></sav></seg><seg><routno>9</routno><subid>1</subid><airline>MU</airline><fltno>5110</fltno><dep>PEK</dep><arr>SHA</arr><dt>10OCT19</dt><week>THU</week><deptm>1200</deptm><arrtm>1420</arrtm><dev>333</dev><stop>0</stop><ASR>^</ASR><meal>D</meal><et>E</et><lnk>DS#</lnk><term><dep>T2</dep><arr>T2</arr></term><flytm>2:20</flytm><journeytm>2:20</journeytm><seatAndNums><seatAndNum><name>J</name><av>A</av></seatAndNum><seatAndNum><name>Y</name><av>A</av></seatAndNum><seatAndNum><name>B</name><av>A</av></seatAndNum><seatAndNum><name>M</name><av>A</av></seatAndNum><seatAndNum><name>E</name><av>A</av></seatAndNum><seatAndNum><name>H</name><av>A</av></seatAndNum><seatAndNum><name>K</name><av>A</av></seatAndNum><seatAndNum><name>L</name><av>A</av></seatAndNum><seatAndNum><name>N</name><av>A</av></seatAndNum><seatAndNum><name>R</name><av>A</av></seatAndNum></seatAndNums><sav><as><service_type>INFT</service_type><control_level>FLIGHT</control_level><service_status><status>OPEN</status><av_num>15</av_num></service_status></as></sav></seg><seg><routno>10</routno><subid>1</subid><airline>MU</airline><fltno>5112</fltno><dep>PEK</dep><arr>SHA</arr><dt>10OCT19</dt><week>THU</week><deptm>1300</deptm><arrtm>1515</arrtm><dev>773</dev><stop>0</stop><ASR>^</ASR><meal>S</meal><et>E</et><lnk>DS#</lnk><term><dep>T2</dep><arr>T2</arr></term><flytm>2:15</flytm><journeytm>2:15</journeytm><seatAndNums><seatAndNum><name>J</name><av>A</av></seatAndNum><seatAndNum><name>Y</name><av>A</av></seatAndNum><seatAndNum><name>B</name><av>A</av></seatAndNum><seatAndNum><name>M</name><av>A</av></seatAndNum><seatAndNum><name>E</name><av>A</av></seatAndNum><seatAndNum><name>H</name><av>A</av></seatAndNum><seatAndNum><name>K</name><av>A</av></seatAndNum><seatAndNum><name>L</name><av>A</av></seatAndNum><seatAndNum><name>N</name><av>A</av></seatAndNum><seatAndNum><name>R</name><av>A</av></seatAndNum></seatAndNums><sav><as><service_type>INFT</service_type><control_level>FLIGHT</control_level><service_status><status>OPEN</status><av_num>15</av_num></service_status></as></sav></seg><seg><routno>11</routno><subid>1</subid><airline>MU</airline><fltno>271</fltno><dep>PEK</dep><arr>PVG</arr><dt>10OCT19</dt><week>THU</week><deptm>1255</deptm><arrtm>1520</arrtm><dev>321</dev><stop>0</stop><ASR>^</ASR><meal>S</meal><et>E</et><lnk>DS#</lnk><term><dep>T2</dep><arr>T1</arr></term><flytm>2:25</flytm><journeytm>2:25</journeytm><seatAndNums><seatAndNum><name>J</name><av>A</av></seatAndNum><seatAndNum><name>Y</name><av>A</av></seatAndNum><seatAndNum><name>B</name><av>A</av></seatAndNum></seatAndNums><sav><as><service_type>INFT</service_type><control_level>FLIGHT</control_level><service_status><status>OPEN</status><av_num>8</av_num></service_status></as></sav></seg><seg><routno>12</routno><subid>1</subid><csmark>*</csmark><airline>MU</airline><fltno>8560</fltno><dep>PEK</dep><arr>SHA</arr><dt>10OCT19</dt><week>THU</week><deptm>1305</deptm><arrtm>1530</arrtm><dev>738</dev><stop>0</stop><ASR>^</ASR><meal>L</meal><et>E</et><cohost>*</cohost><lnk>DS#</lnk><codeshare><airline>MF</airline><fltno>8178</fltno></codeshare><term><dep>T2</dep><arr>T2</arr></term><flytm>2:25</flytm><journeytm>2:25</journeytm><seatAndNums><seatAndNum><name>Y</name><av>A</av></seatAndNum></seatAndNums></seg><seg><routno>13</routno><subid>1</subid><airline>MU</airline><fltno>5154</fltno><dep>PEK</dep><arr>SHA</arr><dt>10OCT19</dt><week>THU</week><deptm>1330</deptm><arrtm>1540</arrtm><dev>738</dev><stop>0</stop><ASR>^</ASR><meal>S</meal><et>E</et><lnk>DS#</lnk><term><dep>T2</dep><arr>T2</arr></term><flytm>2:10</flytm><journeytm>2:10</journeytm><seatAndNums><seatAndNum><name>Y</name><av>A</av></seatAndNum><seatAndNum><name>B</name><av>A</av></seatAndNum><seatAndNum><name>M</name><av>A</av></seatAndNum><seatAndNum><name>E</name><av>A</av></seatAndNum><seatAndNum><name>H</name><av>A</av></seatAndNum><seatAndNum><name>K</name><av>A</av></seatAndNum><seatAndNum><name>L</name><av>A</av></seatAndNum><seatAndNum><name>N</name><av>A</av></seatAndNum><seatAndNum><name>R</name><av>A</av></seatAndNum></seatAndNums><sav><as><service_type>INFT</service_type><control_level>FLIGHT</control_level><service_status><status>OPEN</status><av_num>6</av_num></service_status></as></sav></seg><seg><routno>14</routno><subid>1</subid><airline>MU</airline><fltno>5114</fltno><dep>PEK</dep><arr>SHA</arr><dt>10OCT19</dt><week>THU</week><deptm>1400</deptm><arrtm>1620</arrtm><dev>33L</dev><stop>0</stop><ASR>^</ASR><meal>S</meal><et>E</et><lnk>DS#</lnk><term><dep>T2</dep><arr>T2</arr></term><flytm>2:20</flytm><journeytm>2:20</journeytm><seatAndNums><seatAndNum><name>J</name><av>A</av></seatAndNum><seatAndNum><name>W</name><av>A</av></seatAndNum><seatAndNum><name>Y</name><av>A</av></seatAndNum><seatAndNum><name>B</name><av>A</av></seatAndNum></seatAndNums><sav><as><service_type>INFT</service_type><control_level>FLIGHT</control_level><service_status><status>OPEN</status><av_num>15</av_num></service_status></as></sav></seg><seg><routno>15</routno><subid>1</subid><airline>MU</airline><fltno>5116</fltno><dep>PEK</dep><arr>SHA</arr><dt>10OCT19</dt><week>THU</week><deptm>1500</deptm><arrtm>1720</arrtm><dev>33L</dev><stop>0</stop><ASR>^</ASR><meal>S</meal><et>E</et><lnk>DS#</lnk><term><dep>T2</dep><arr>T2</arr></term><flytm>2:20</flytm><journeytm>2:20</journeytm><seatAndNums><seatAndNum><name>J</name><av>A</av></seatAndNum><seatAndNum><name>W</name><av>A</av></seatAndNum><seatAndNum><name>Y</name><av>A</av></seatAndNum><seatAndNum><name>B</name><av>A</av></seatAndNum></seatAndNums><sav><as><service_type>INFT</service_type><control_level>FLIGHT</control_level><service_status><status>OPEN</status><av_num>15</av_num></service_status></as></sav></seg><seg><routno>16</routno><subid>1</subid><airline>MU</airline><fltno>5118</fltno><dep>PEK</dep><arr>SHA</arr><dt>10OCT19</dt><week>THU</week><deptm>1600</deptm><arrtm>1820</arrtm><dev>33L</dev><stop>0</stop><ASR>^</ASR><meal>S</meal><et>E</et><lnk>DS#</lnk><term><dep>T2</dep><arr>T2</arr></term><flytm>2:20</flytm><journeytm>2:20</journeytm><seatAndNums><seatAndNum><name>J</name><av>A</av></seatAndNum><seatAndNum><name>W</name><av>A</av></seatAndNum><seatAndNum><name>Y</name><av>A</av></seatAndNum><seatAndNum><name>B</name><av>A</av></seatAndNum><seatAndNum><name>H</name><av>A</av></seatAndNum></seatAndNums><sav><as><service_type>INFT</service_type><control_level>FLIGHT</control_level><service_status><status>OPEN</status><av_num>15</av_num></service_status></as></sav></seg><seg><routno>17</routno><subid>1</subid><airline>MU</airline><fltno>5120</fltno><dep>PEK</dep><arr>SHA</arr><dt>10OCT19</dt><week>THU</week><deptm>1700</deptm><arrtm>1915</arrtm><dev>333</dev><stop>0</stop><ASR>^</ASR><meal>D</meal><et>E</et><lnk>DS#</lnk><term><dep>T2</dep><arr>T2</arr></term><flytm>2:15</flytm><journeytm>2:15</journeytm><seatAndNums><seatAndNum><name>J</name><av>A</av></seatAndNum><seatAndNum><name>Y</name><av>A</av></seatAndNum><seatAndNum><name>B</name><av>A</av></seatAndNum></seatAndNums><sav><as><service_type>INFT</service_type><control_level>FLIGHT</control_level><service_status><status>OPEN</status><av_num>15</av_num></service_status></as></sav></seg><seg><routno>18</routno><subid>1</subid><airline>MU</airline><fltno>563</fltno><dep>PEK</dep><arr>PVG</arr><dt>10OCT19</dt><week>THU</week><deptm>1715</deptm><arrtm>1930</arrtm><dev>33L</dev><stop>0</stop><ASR>^</ASR><meal>D</meal><et>E</et><lnk>DS#</lnk><term><dep>T2</dep><arr>T1</arr></term><flytm>2:15</flytm><journeytm>2:15</journeytm><seatAndNums><seatAndNum><name>J</name><av>A</av></seatAndNum><seatAndNum><name>W</name><av>A</av></seatAndNum><seatAndNum><name>Y</name><av>A</av></seatAndNum></seatAndNums><sav><as><service_type>INFT</service_type><control_level>FLIGHT</control_level><service_status><status>OPEN</status><av_num>15</av_num></service_status></as></sav></seg><seg><routno>19</routno><subid>1</subid><airline>MU</airline><fltno>5122</fltno><dep>PEK</dep><arr>SHA</arr><dt>10OCT19</dt><week>THU</week><deptm>1800</deptm><arrtm>2015</arrtm><dev>33L</dev><stop>0</stop><ASR>^</ASR><meal>D</meal><et>E</et><lnk>DS#</lnk><term><dep>T2</dep><arr>T1</arr></term><flytm>2:15</flytm><journeytm>2:15</journeytm><seatAndNums><seatAndNum><name>J</name><av>A</av></seatAndNum><seatAndNum><name>W</name><av>A</av></seatAndNum><seatAndNum><name>Y</name><av>A</av></seatAndNum><seatAndNum><name>B</name><av>A</av></seatAndNum></seatAndNums><sav><as><service_type>INFT</service_type><control_level>FLIGHT</control_level><service_status><status>OPEN</status><av_num>15</av_num></service_status></as></sav></seg><seg><routno>20</routno><subid>1</subid><csmark>*</csmark><airline>MU</airline><fltno>9108</fltno><dep>PEK</dep><arr>SHA</arr><dt>10OCT19</dt><week>THU</week><deptm>1830</deptm><arrtm>2050</arrtm><dev>73L</dev><stop>0</stop><ASR>^</ASR><meal>D</meal><et>E</et><cohost>*</cohost><lnk>DS#</lnk><codeshare><airline>FM</airline><fltno>9108</fltno></codeshare><term><dep>T2</dep><arr>T2</arr></term><flytm>2:20</flytm><journeytm>2:20</journeytm><seatAndNums><seatAndNum><name>J</name><av>A</av></seatAndNum><seatAndNum><name>W</name><av>A</av></seatAndNum><seatAndNum><name>Y</name><av>A</av></seatAndNum><seatAndNum><name>B</name><av>A</av></seatAndNum><seatAndNum><name>H</name><av>A</av></seatAndNum></seatAndNums><sav><as><service_type>INFT</service_type><control_level>FLIGHT</control_level><service_status><status>OPEN</status><av_num>6</av_num></service_status></as></sav></seg><seg><routno>21</routno><subid>1</subid><airline>MU</airline><fltno>5124</fltno><dep>PEK</dep><arr>SHA</arr><dt>10OCT19</dt><week>THU</week><deptm>1900</deptm><arrtm>2115</arrtm><dev>33L</dev><stop>0</stop><ASR>^</ASR><meal>S</meal><et>E</et><lnk>DS#</lnk><term><dep>T2</dep><arr>T2</arr></term><flytm>2:15</flytm><journeytm>2:15</journeytm><seatAndNums><seatAndNum><name>J</name><av>A</av></seatAndNum><seatAndNum><name>W</name><av>A</av></seatAndNum><seatAndNum><name>Y</name><av>A</av></seatAndNum><seatAndNum><name>B</name><av>A</av></seatAndNum></seatAndNums><sav><as><service_type>INFT</service_type><control_level>FLIGHT</control_level><service_status><status>OPEN</status><av_num>15</av_num></service_status></as></sav></seg><seg><routno>22</routno><subid>1</subid><airline>MU</airline><fltno>5130</fltno><dep>PEK</dep><arr>PVG</arr><dt>10OCT19</dt><week>THU</week><deptm>1935</deptm><arrtm>2210</arrtm><dev>323</dev><stop>0</stop><ASR>^</ASR><meal>S</meal><et>E</et><lnk>DS#</lnk><term><dep>T2</dep><arr>T1</arr></term><flytm>2:35</flytm><journeytm>2:35</journeytm><seatAndNums><seatAndNum><name>J</name><av>A</av></seatAndNum><seatAndNum><name>Y</name><av>A</av></seatAndNum><seatAndNum><name>B</name><av>A</av></seatAndNum><seatAndNum><name>H</name><av>A</av></seatAndNum></seatAndNums><sav><as><service_type>INFT</service_type><control_level>FLIGHT</control_level><service_status><status>OPEN</status><av_num>8</av_num></service_status></as></sav></seg><seg><routno>23</routno><subid>1</subid><airline>MU</airline><fltno>5126</fltno><dep>PEK</dep><arr>SHA</arr><dt>10OCT19</dt><week>THU</week><deptm>2000</deptm><arrtm>2215</arrtm><dev>333</dev><stop>0</stop><ASR>^</ASR><meal>S</meal><et>E</et><lnk>DS#</lnk><term><dep>T2</dep><arr>T2</arr></term><flytm>2:15</flytm><journeytm>2:15</journeytm><seatAndNums><seatAndNum><name>J</name><av>A</av></seatAndNum><seatAndNum><name>Y</name><av>A</av></seatAndNum><seatAndNum><name>B</name><av>A</av></seatAndNum><seatAndNum><name>H</name><av>A</av></seatAndNum></seatAndNums><sav><as><service_type>INFT</service_type><control_level>FLIGHT</control_level><service_status><status>OPEN</status><av_num>15</av_num></service_status></as></sav></seg><seg><routno>24</routno><subid>1</subid><csmark>*</csmark><airline>MU</airline><fltno>9102</fltno><dep>PEK</dep><arr>SHA</arr><dt>10OCT19</dt><week>THU</week><deptm>2020</deptm><arrtm>2250</arrtm><dev>73E</dev><stop>0</stop><ASR>^</ASR><meal>S</meal><et>E</et><cohost>*</cohost><lnk>DS#</lnk><codeshare><airline>FM</airline><fltno>9102</fltno></codeshare><term><dep>T2</dep><arr>T2</arr></term><flytm>2:30</flytm><journeytm>2:30</journeytm><seatAndNums><seatAndNum><name>Y</name><av>A</av></seatAndNum><seatAndNum><name>B</name><av>A</av></seatAndNum><seatAndNum><name>H</name><av>A</av></seatAndNum></seatAndNums><sav><as><service_type>INFT</service_type><control_level>FLIGHT</control_level><service_status><status>OPEN</status><av_num>6</av_num></service_status></as></sav></seg><seg><routno>25</routno><subid>1</subid><airline>MU</airline><fltno>5128</fltno><dep>PEK</dep><arr>SHA</arr><dt>10OCT19</dt><week>THU</week><deptm>2105</deptm><arrtm>2320</arrtm><dev>773</dev><stop>0</stop><ASR>^</ASR><et>E</et><lnk>DS#</lnk><term><dep>T2</dep><arr>T2</arr></term><flytm>2:15</flytm><journeytm>2:15</journeytm><seatAndNums><seatAndNum><name>F</name><av>A</av></seatAndNum><seatAndNum><name>J</name><av>A</av></seatAndNum><seatAndNum><name>Y</name><av>A</av></seatAndNum><seatAndNum><name>B</name><av>A</av></seatAndNum><seatAndNum><name>M</name><av>A</av></seatAndNum><seatAndNum><name>E</name><av>A</av></seatAndNum><seatAndNum><name>H</name><av>A</av></seatAndNum><seatAndNum><name>K</name><av>A</av></seatAndNum><seatAndNum><name>L</name><av>A</av></seatAndNum><seatAndNum><name>N</name><av>A</av></seatAndNum><seatAndNum><name>R</name><av>A</av></seatAndNum></seatAndNums><sav><as><service_type>INFT</service_type><control_level>FLIGHT</control_level><service_status><status>OPEN</status><av_num>15</av_num></service_status></as></sav></seg><seg><routno>26</routno><subid>1</subid><airline>MU</airline><fltno>5158</fltno><dep>PEK</dep><arr>SHA</arr><dt>10OCT19</dt><week>THU</week><deptm>2130</deptm><arrtm>2345</arrtm><dev>738</dev><stop>0</stop><ASR>^</ASR><et>E</et><lnk>DS#</lnk><term><dep>T2</dep><arr>T2</arr></term><flytm>2:15</flytm><journeytm>2:15</journeytm><seatAndNums><seatAndNum><name>Y</name><av>A</av></seatAndNum><seatAndNum><name>B</name><av>A</av></seatAndNum><seatAndNum><name>M</name><av>A</av></seatAndNum><seatAndNum><name>E</name><av>A</av></seatAndNum><seatAndNum><name>H</name><av>A</av></seatAndNum><seatAndNum><name>K</name><av>A</av></seatAndNum><seatAndNum><name>L</name><av>A</av></seatAndNum><seatAndNum><name>N</name><av>A</av></seatAndNum><seatAndNum><name>R</name><av>A</av></seatAndNum></seatAndNums><sav><as><service_type>INFT</service_type><control_level>FLIGHT</control_level><service_status><status>OPEN</status><av_num>6</av_num></service_status></as></sav></seg><seg><routno>27</routno><subid>1</subid><airline>MU</airline><fltno>5160</fltno><dep>PEK</dep><arr>SHA</arr><dt>10OCT19</dt><week>THU</week><deptm>2150</deptm><arrtm>2355</arrtm><dev>33L</dev><stop>0</stop><ASR>^</ASR><et>E</et><lnk>DS#</lnk><term><dep>T2</dep><arr>T2</arr></term><flytm>2:05</flytm><journeytm>2:05</journeytm><seatAndNums><seatAndNum><name>J</name><av>A</av></seatAndNum><seatAndNum><name>W</name><av>A</av></seatAndNum><seatAndNum><name>Y</name><av>A</av></seatAndNum><seatAndNum><name>B</name><av>A</av></seatAndNum><seatAndNum><name>M</name><av>A</av></seatAndNum><seatAndNum><name>E</name><av>A</av></seatAndNum><seatAndNum><name>H</name><av>A</av></seatAndNum><seatAndNum><name>K</name><av>A</av></seatAndNum><seatAndNum><name>L</name><av>A</av></seatAndNum><seatAndNum><name>N</name><av>A</av></seatAndNum><seatAndNum><name>R</name><av>A</av></seatAndNum></seatAndNums><sav><as><service_type>INFT</service_type><control_level>FLIGHT</control_level><service_status><status>OPEN</status><av_num>15</av_num></service_status></as></sav></seg><seg><routno>28</routno><subid>1</subid><airline>MU</airline><fltno>5390</fltno><dep>PEK</dep><arr>SHA</arr><dt>10OCT19</dt><week>THU</week><deptm>1310</deptm><arrtm>1810</arrtm><dev>325</dev><stop>1</stop><ASR>^</ASR><et>E</et><lnk>DS#</lnk><term><dep>T2</dep><arr>T2</arr></term><flytm>5:00</flytm><journeytm>5:00</journeytm><seatAndNums><seatAndNum><name>J</name><av>A</av></seatAndNum><seatAndNum><name>Y</name><av>A</av></seatAndNum><seatAndNum><name>B</name><av>A</av></seatAndNum><seatAndNum><name>M</name><av>A</av></seatAndNum><seatAndNum><name>E</name><av>A</av></seatAndNum><seatAndNum><name>H</name><av>A</av></seatAndNum><seatAndNum><name>K</name><av>A</av></seatAndNum></seatAndNums><sav><as><service_type>INFT</service_type><control_level>FLIGHT</control_level><service_status><status>OPEN</status><av_num>8</av_num></service_status></as></sav></seg></segs><h3ads><h3ad>KiogIEhVIEZMSUdIVCBQTEVBU0UgQ0hFQ0sgSU4gNDUgTUlOVVRFUyBCRUZPUkUgREVQQVJUVVJFIEFUIFBFSw==</h3ad><h3ad>KiogIFNDIEZMSUdIVCBQTEVBU0UgQ0hFQ0sgSU4gNDUgTUlOVVRFUyBCRUZPUkUgREVQQVJUVVJFIEFUIFBFSyBUMw==</h3ad><h3ad>KiogIEFsbCBzY2hlZHVsZWQgTVUgb3IgRk0gZmxpZ2h0cyBvcGVyYXRlZCBieSBNVSBvciBGTQ==</h3ad></h3ads></out1></Response></OTA_AVE_RS>";
        //读取XML标签信息
        Document doc= DocumentHelper.parseText(x);
        JSONObject json=new JSONObject();
        //通过工具类把读取到的信息转成json数据
        Xml2JsonUtil.dom4j2Json(doc.getRootElement(), json);
        System.out.println(json);
        String response = json.getString("Response");
        //最后转换成实体类对象
        Response response2 = JSONObject.parseObject(response, Response.class);

        System.out.println(response2);


    }
 }

执行结果:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值