'javax.xml.bind.UnmarshalException - with linked exception:

I have got receive an xml inputstream with a URLConnection. However when i try to unmarshall the inputstream. It throw an exception. javax.xml.bind.UnmarshalException - with linked exception: [javax.xml.stream.XMLStreamException: ParseError at [row,col]:[53088,40] Message: The reference to entity "T" must end with the ';' delimiter.]

CODE:

try {
    URL url = new URL(hostURL);  
    URLConnection urlConnection = url.openConnection();  
    urlConnection.setRequestProperty("Accept", "application/xml");
    urlConnection.setRequestProperty("Authorization", "Basic " + authDetails);

    InputStream inputStream = urlConnection.getInputStream();

    XMLInputFactory xif = XMLInputFactory.newInstance();
    xif.setProperty("javax.xml.stream.isCoalescing", true); 
    XMLStreamReader xsr = xif.createXMLStreamReader(inputStream);

     // Advance to the "Packages" element.
     while(xsr.hasNext()) {
         if(xsr.isStartElement() && "packages".equals(xsr.getLocalName())) {
             break;
         }
         xsr.next();
      }

     JAXBContext jaxbContext = JAXBContext.newInstance(Packages.class);
     Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
     packages = (Packages) jaxbUnmarshaller.unmarshal(xsr);
    }catch (JAXBException e) {
     e.printStackTrace();
    }catch (MalformedURLException e) {
     e.printStackTrace();
    }catch (IOException e) {
     e.printStackTrace();
    }catch(Exception e){
     e.printStackTrace();
     }finally{

    }

PS: [row,col]:[53088,40] = newproductsite for T&T evol

you can find Stack traces in link http://pastebin.com/LuhbnMQq

Guys am new to this thing and stuck with it, any help would be appreciated

BR Sara



Solution 1:[1]

Your XML file isn't well-formed.

newproductsite for T&T evol

You cannot have a '&' in the XML file, it must be represented as

&

How was the XML produced? The error is there...

Solution 2:[2]

Your xml input is not well formed. In the text newproductsite for T&T evol the ampersand is a reserved character. It is used for escaping (e.g. &lt; represents the < sign or &#x41; is the letter A. So, after the & in the text, the parser expects a value and a ; to see that the escape sequence is finished. If you want to use the ampersand in your xml elements, it must be escaped e.g. by &amp;.

To fix the problem the source needs to produce either well-formed xml or you need to sanitize the data you received before processing it. I would recommend the first.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 laune
Solution 2 Ralf Wagner