1

Can anyone help me to figure out the root cause for this issue.

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/**/">

Code :

      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);

Class:

@XmlRootElement(name = "entry")
@XmlAccessorType(XmlAccessType.FIELD)
public class Entry {

Exception:

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)
2
  • Make sure your XML doesn't have a BOM at the start. Your XML is also missing a closing root tag. Dec 29, 2016 at 6:14
  • checked the xml file and no junk characters. @approxiblue
    – Spartan
    Dec 29, 2016 at 6:15

1 Answer 1

1

Convert your string below :

 byte[] metaBytes = metaData.getBytes();
 String input = new String(metaBytes, "UTF-8");

Use SAX Parser

      SAXParserFactory parserFactory;
      parserFactory = SAXParserFactory.newInstance();
      parserFactory.setNamespaceAware(false);
      XMLReader reader = parserFactory.newSAXParser().getXMLReader();
      Source er = new SAXSource(reader, new InputSource(new StringReader(input)));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.