0

I have XML file which I want to convert it into the Object. The XML is as follows

<Response>
     <result xsi:type="TestResponse">
        <description xsi:type="xsd:string">Hello world</description>
        <name xsi:type="xsd:string">John</name>
        <success xsi:type="xsd:boolean">true</success>
     </result>
  </Response>

I have tried the approach like

XStream stream = new XStream(new DomDriver());
stream.alias("result", Response.class); 
Response response = (Response) stream.fromXML(xmlStr);

It's throwing exception like :   `Content is not allowed in prolog`

Response.java is like

public class Response{
  private String description;
  private String name;
  private boolean success;

//setter and getter methods
}
tarzanbappa
  • 4,930
  • 22
  • 75
  • 117
Samraan
  • 204
  • 1
  • 2
  • 14
  • Possible duplicate of [Content is not allowed in Prolog SAXParserException](http://stackoverflow.com/questions/4569123/content-is-not-allowed-in-prolog-saxparserexception) – Scorpio Oct 06 '15 at 10:23

2 Answers2

0

Your problem is most likely caused by characters at the beginning of your XML. These are not necessarily visible, you could be stuck with a byte order mark (BOM). This might happen if you open your XML with editors that do not honor encodings well (the Windows Editor, Notepad, or similar).

Try resaving it specifically as UTF-8, and add

<?xml version="1.0" encoding="UTF-8"?>

on top, maybe that'll fix it for you.

Scorpio
  • 2,309
  • 1
  • 27
  • 45
-1

If that is the full xml file, you are missing the header:

for example:

<?xml version="1.0" encoding="UTF-8"?>
Balder
  • 8,623
  • 4
  • 39
  • 61
  • This is not the full xml, I have mentioned here only this part, but in actually the above suggested tag is there in the xml – Samraan Oct 06 '15 at 13:02