【发布时间】:2017-05-13 09:59:19
【问题描述】:
谁能帮我找出这个问题的根本原因。
XML:
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xml:base="https://*******/odata/**/">
代码:
jaxbContext = JAXBContext.newInstance(Entry.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
XMLInputFactory xif = XMLInputFactory.newFactory();
xif.setProperty(XMLInputFactory.SUPPORT_DTD, false);
XMLStreamReader xsr = xif.createXMLStreamReader(new StreamSource(metaData));
Entry entry = (Entry) jaxbUnmarshaller.unmarshal(xsr);
类:
@XmlRootElement(name = "entry")
@XmlAccessorType(XmlAccessType.FIELD)
public class Entry {
例外:
javax.xml.bind.UnmarshalException
- with linked exception:
[javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1]
Message: Content is not allowed in prolog.]
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(Unknown Source)
【问题讨论】:
-
确保您的 XML 没有 a BOM at the start。您的 XML 也缺少结束根标记。
-
检查了 xml 文件,没有垃圾字符。 @近似蓝