[英]org.xml.sax.SAXParseException: Premature end of file with jaxbUnmarshaller
This is a java method which unmarshalls xml file. 这是一个将XML文件解组的Java方法。
I looked for several problems with this error but I couldn't find an answer. 我寻找了与此错误有关的几个问题,但找不到答案。
@WebMethod(operationName = "List_Flights")
public List<FlightAvailableOffers> List_Flights() {//ArrayList<String[]>
FlightAvailableOffers flighte = new FlightAvailableOffers();
Flights flight = new Flights();
List<FlightAvailableOffers> bookingAvailFlights = flight.getOffersBooking();
try {
File file = new File("Flight_Bookings.xml");
JAXBContext jaxbContext = JAXBContext.newInstance(FlightAvailableOffers.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
flight = (Flights)jaxbUnmarshaller.unmarshal(file);
//List<FlightAvailableOffers> bookingAvailFlights = flight.getOffersBooking();
FlightAvailableOffers booking = new FlightAvailableOffers();
Iterator itr = bookingAvailFlights.iterator();
while (itr.hasNext()) {
booking = (FlightAvailableOffers) itr.next();
bookingAvailFlights.add(booking);
}
} catch (JAXBException e) {
System.out.println(e.getCause());
}
return bookingAvailFlights;
}
}
But when I run this it shows this message 但是当我运行它时会显示此消息
"org.xml.sax.SAXParseException: Premature end of file with jaxbUnmarshaller"
“ org.xml.sax.SAXParseException:带有jaxbUnmarshaller的文件过早结束”
Can anyone help me to get rid of this? 谁能帮我摆脱这个困扰?
There is an error in flightinfo.xsd. flightinfo.xsd中存在错误。 The tns: namespace is declared in the document..
tns:名称空间在文档中声明。
Recorded reason: UndeclaredPrefix: Cannot resolve 'tns:FlightAvailableOffers' as a QName: the prefix 'tns' is not declared 记录的原因:UndeclaredPrefix:无法将'tns:FlightAvailableOffers'解析为QName:未声明前缀'tns'
Hint: 暗示:
You can validate your xml against xsd through online tools. 您可以通过在线工具针对xsd验证xml。
I would recommend the below one.. XML Validation against XML Schema Document 我会推荐以下一种。. 针对XML模式文档的XML验证
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.