Parsing sunstax、JAXB和关闭对DTD/XSD/schema的验证
我们将JAXB与STAXmlEventReaderAPI结合使用,以解析和提取通过REST调用检索到的xml数据Parsing sunstax、JAXB和关闭对DTD/XSD/schema的验证,parsing,jboss,jaxb,stax,validating,Parsing,Jboss,Jaxb,Stax,Validating,我们将JAXB与STAXmlEventReaderAPI结合使用,以解析和提取通过REST调用检索到的xml数据 InputStream responseStream = response.getEntityInputStream(); if (responseStream != null) { XMLInputFactory xmlif = XMLInputFactory.newInstance(); // stax API
InputStream responseStream = response.getEntityInputStream();
if (responseStream != null)
{
XMLInputFactory xmlif = XMLInputFactory.newInstance();
// stax API
XMLEventReader xmler = xmlif.createXMLEventReader(new InputStreamReader(responseStream));
EventFilter filter = new EventFilter() {
public boolean accept(XMLEvent event) {
return event.isStartElement();
}
};
XMLEventReader xmlfer = xmlif.createFilteredReader(xmler, filter);
xmlfer.nextEvent();
// use jaxb
JAXBContext ctx = JAXBContext.newInstance(Summary.class);
Unmarshaller um = ctx.createUnmarshaller();
while (xmlfer.peek() != null) {
JAXBElement<CustomObject> se = um.unmarshal(xmler,
CustomObject.class);
CustomObject = se.getValue();
}
responseStream.close();
} else {
logger.error("InputStream response from API is null. No data to process");
}
response.close();
}
因为setValidating是一种不推荐使用的方法
关于如何进行这项工作,有什么想法/建议吗?我们的假设正确吗?这可能是已知的JBoss问题吗 错误消息看起来像是解析器消息,您确定文档有效吗?您能发布完整的堆栈跟踪和XML文档吗?
um.setValidating(false);