<BADFM>
<Order >
<Ord OrdQty="1" faft="O">
<Bag pakka="1" DSE="C"/>
</Ord>
</Order>
</BADFM>
=================JAXB:從XML到Java的數據綁定是不是跟這個結構發生
@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;
}
}
========================
它返回我空,當我試圖訪問
系統.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);
我已經添加了它在我的問題(解析器類) – Pawan 2012-04-04 13:50:22