6
我有一位客戶,我建立了訪問Web服務。我正在使用一些JAXB生成的類(Netbeans 6.9)來解組我的xml數據。JAXB解編忽略SOAP信封/頭標記
試圖解組此WebService的InputStream的迴應時,我收到意想不到的元素的錯誤,我也得到同樣的意外因素的錯誤,如果我保存到一個文件的響應。
javax.xml.bind.UnmarshalException: unexpected element (uri:"http://www.w3.org/2003/05/soap-envelope", local:"Envelope"). Expected elements are <{http://www.cmicdataservices.com/}Authentication>,....
隨着保存到文件我可以進去刪除SOAP標籤(信封,體,HEADR),然後運行沒有問題,解組數據。
我還沒有真正找到一個方法,使拆封忽略這些標記。有誰知道可以做些什麼來忽略這些標籤?
下面是主要的方法和通過該流返回的類。
public static void main(String[] args) {
JAXBContext jaxbContext = null;
try {
CMICData cmic = new CMICData();
jaxbContext = JAXBContext.newInstance("cmic.ajrs.com");
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
GetCurrentDataVer1Response response = (GetCurrentDataVer1Response)
unmarshaller.unmarshal(cmic.getCMICIs("GetCurrentDataVer1"));
DatacenterDataVer1 dataSet = response.getGetCurrentDataVer1Result();
List products = dataSet.getAProductBase().getProductBase();
// print some primary keys to show data being processed.
for(Iterator<ProductBase> iter = products.iterator(); iter.hasNext();) {
ProductBase pb = iter.next();
System.out.println(pb.getPkID());
}
} catch (JAXBException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
Netbeans生成的類。
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"getCurrentDataVer1Result"
})
@XmlRootElement(name = "GetCurrentDataVer1Response", namespace = "http://www.cmicdataservices.com/")
public class GetCurrentDataVer1Response {
@XmlElement(name = "GetCurrentDataVer1Result")
protected DatacenterDataVer1 getCurrentDataVer1Result;
/**
* Gets the value of the getCurrentDataVer1Result property.
*
* @return
* possible object is
* {@link DatacenterDataVer1 }
*
*/
public DatacenterDataVer1 getGetCurrentDataVer1Result() {
return getCurrentDataVer1Result;
}
/**
* Sets the value of the getCurrentDataVer1Result property.
*
* @param value
* allowed object is
* {@link DatacenterDataVer1 }
*
*/
public void setGetCurrentDataVer1Result(DatacenterDataVer1 value) {
this.getCurrentDataVer1Result = value;
}
}
看到這裏http://stackoverflow.com/questions/5044042/jaxb-ignore-element – laz 2011-04-06 16:41:15