我正在調用的JAX-RS Web服務將xml內容作爲文本/ html內容類型拋出。在我這邊,我需要讀取xml,並將其轉換爲Java對象。帶格式錯誤的解組JAX-RS響應xml(content-type:text/xml)
問題是:響應xml格式不正確,在錯誤位置有換行符,例如 - 在<?xml version="1.0" encoding="UTF-8"?>
之前有幾個換行符。這是試圖解開它的問題。
有沒有一種方法可以解組響應xml字符串,雖然它有格式化問題?
在此先感謝。
HttpGet httpGet = new HttpGet(uri);
HttpResponse response = client.execute(httpGet);
InputStream inputStream = response.getEntity().getContent();
JAXBContext context = JAXBContext.newInstance(MyClass.class);
MyClass myObj = (MyClass) context.createUnmarshaller().unmarshal(inputStream);
您能否顯示與此事有關的代碼? – imwill
@imwill:已添加。 – James
裏面還有格式化問題嗎?或者在<?xml ..之前? – imwill