<BADFM>
<Order >
<Ord OrdQty="1" faft="O">
<Bag pakka="1" DSE="C"/>
</Ord>
</Order>
</BADFM>
==================
@XmlRootElement(name="BADFM")
public class Message
{
@XmlElement(name="Order")
private MobBlock mob;
public MobBlock getMob() {
return mob;
}
public void setmob(MobBlock mob) {
this.mob = mob;
}
}
===================
public class MobBlock {
private Ord ord;
@XmlElement(name="Ord")
public Ord getOrd() {
return ord;
}
public void setOrd(Ord ord) {
this.ord = ord;
}
}
====================
public class Ord {
private Bagger Bagger;
@XmlElement(name="Bag")
public Bagger getBagger() {
return Bagger;
}
public void setBagger(Bagger Bagger) {
this.Bagger = Bagger;
}
}
========================
public class Bagger {
private String dsc;
@XmlAttribute(name = "DSE")
public String getDSE() {
return dsc;
}
public void setDSE(String dsc) {
this.dsc = dsc;
}
}
=========================
当我尝试访问时,它返回我 null
System.out.println(m.getMob().getOrd().getBagger().getDSE());
有人可以告诉我有什么问题吗?
这是我的解析器类
public class BadFmParser
{
public static AbstractMessageT parse(String Str) throws Exception {
private static JAXBContext jc = null;
jc = JAXBContext.newInstance("mypackage");
Unmarshaller um = jc.createUnmarshaller();
BADFM badfmMessage = (BADFM) um.unmarshal(new StringReader(Str));
JAXBElement<? extends Message> element = badfmMessage.getMessage();
return element.getValue();
}
我这样称呼它
Message message = BADFMParser.parse(XMLFile);