gpt4 book ai didi

java - 如何在解码时捕获多次出现的 xml 到 pojo?

转载 作者:行者123 更新时间:2023-12-02 10:23:46 25 4
gpt4 key购买 nike

只是想学习和理解 Jaxb 以及 xml 绑定(bind)的工作原理,所以非常非常感谢!我不明白它如何或是否会重复出现 block 或部分?在下面,MM block 可以是1个或多个,这是如何吸收到pojo的? Jaxb 或其他引擎如何绑定(bind)多个部分,例如 MM 部分?谢谢!!!

我有一个 XML 文件,需要 UnMarshal 为 Java POJO。

A   018912111835030108XXXXXXXXXX
<RTR>
<HEAD>
<IDCMS pn="ABF31A6FNCL0004" vers="4.0"/>
<DA>2018/12/11 01:07:37</DA>
<ACD MSN="0149" tail="N503DN" type="A350-900"/>
<TID>C00000011</TID>
</HEAD>
<HEADRTR>
<FROM>KDTW</FROM>
<TO>ZBAA</TO>
<FNBR>DAL189 </FNBR>
</HEADRTR>
<ITD>
<CB>A</CB>
<NFDE>
<MC>3166X001</MC>
<MD>INDICATING-OIS CAPT-&quot;OIS NOT AVAIL&quot; displayed instead of the requested video</MD>
</NFDE>
<MM hdi="y" fo="A" occ="1">
<MC>4612F11W</MC>
<MD>VGM-1(107TC1) / AVM-1(103TC1) / OSFC RESET</MD>
<DA>2018/12/11 00:57:39</DA>
<ATA>4612</ATA>
<FPH>8</FPH>
<FCL>1</FCL>
<PRIO>high</PRIO>
<STA>1</STA>
<SYS name="ASF" bite_id="107" side="0"/>
</MM>
<MM hdi="y" occ="1">
<MC>3166F8TT</MC>
<MD>VGM-1(107TC1) / CMV-2(1TE2) / WRG TO CMV-2(1TE2) PIN AEDD</MD>
<DA>2018/12/11 00:57:36</DA>
<CDA>2018/12/11 00:57:37</CDA>
<ATA>3166</ATA>
<FPH>8</FPH>
<FCL>1</FCL>
<PRIO>low</PRIO>
<STA>2</STA>
<SYS name="CMV2" bite_id="31" side="2"/>
</MM>
</ITD>
</RTR>

为 XML 结构创建了类,减去如何使用重复出现的部分。我不会将它们全部发布。我认为对其中一个人的帮助也会对其他人有所帮助。谢谢!

@XmlRootElement( name = "MM" )
public class Mm {

private String mc;
private String md;
private String da;
private String ata;
private String fph;
private String prio;

Mm(){
super();
}

Mm( @XmlElement(name="MC") String mc,
@XmlElement(name="MD") String md,
@XmlElement(name="DA") String da,
@XmlElement(name="FPH") String fph,
@XmlElement(name="PRIO") String prio) {
this.mc = mc;
this.md = md;
this.da = da;
this.fph = fph;
this.prio = prio;
}

public String getMc() {
return mc;
}
public String getMd() {
return md;
}
public String getDa() {
return da;
}
public String getAta() {
return ata;
}
public String getFph() {
return fph;
}
public String getPrio() {
return prio;
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("MC=");
sb.append(getMc()).append(",");
sb.append("MD=").append(getMd()).append(",");
sb.append("DA=").append(getDa()).append(",");
sb.append("ATA=").append(getAta()).append(",");
sb.append("FPH=").append(getFph()).append(",");
sb.append("PRIO=").append(getPrio());

return sb.toString();
}

}

  @XmlRootElement( name = "FDE" )
public class Fde {

private String mc;
private String md;
private String da;
private String fph;

Fde(){
super();
}

Fde( @XmlElement(name="MC") String mc,
@XmlElement(name="MD") String md,
@XmlElement(name="DA") String da,
@XmlElement(name="FPH") String fph) {
this.mc = mc;
this.md = md;
this.da = da;
this.fph = fph;
}

public String getMc() {
return mc;
}
public String getMd() {
return md;
}
public String getDa() {
return da;
}
public String getFph() {
return fph;
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("MC=");
sb.append(getMc()).append(",");
sb.append("MD=").append(getMd()).append(",");
sb.append("DA=").append(getDa()).append(",");
sb.append("FPH=").append(getFph());

return sb.toString();
}
}

@XmlRootElement( name = "HEADRTR" )
public class HeadRtr {

private String from;
private String to;
private String fnbr;

HeadRtr(){
super();
}

HeadRtr(@XmlElement(name="FROM") String from,
@XmlElement(name="TO") String to,
@XmlElement(name="FNBR") String fnbr) {
this.from = from;
this.to = to;
this.fnbr = fnbr;
}
public String getFrom() {
return from;
}
public String getTo() {
return to;
}
public String getFnbr() {
return fnbr;
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("FROM=");
sb.append(getFrom()).append(",");
sb.append("TO=").append(getTo()).append(",");
sb.append("FNBR=").append(getFnbr());

return sb.toString();
}

}

我正在考虑这些对象的列表

最佳答案

从xml看。您需要 ITD、FDE、MM 作为对象。 ITD 拥有一个列表,FDE 为成员。

关于java - 如何在解码时捕获多次出现的 xml 到 pojo?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54136998/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com