title: Java XML Unmarshalling fails on ampersand (&amp;) using JAXB
body: <p>I have the following XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;details&gt;
    ...
    &lt;address1&gt;Test&amp;amp;Address&lt;/address1&gt;
    ...
  &lt;/details&gt;
  </code></pre>
  
  <p>When I try to unmarshal it using JAXB, it throws the following exception:</p>
  
  <pre><code>Caused by: org.xml.sax.SAXParseException: The reference to entity "Address" must end with the ';' delimiter.
          at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
          at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
          at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
          at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
          at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown Source)
          at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEntityReference(Unknown Source)
          at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
          at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
          at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
          at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
          at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
          at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
          at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
          at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:194)
  </code></pre>
  
  <p>But when I changed the <code>&amp;amp;</code> in the XML to <code>&amp;apos;</code>, it works. Looks like the problem is only with ampersand <code>&amp;amp;</code> and I cannot understand why.</p>
  
  <p>The code to unmarshal is:</p>
  
  <pre><code>JAXBContext context = JAXBContext.newInstance("some.package.name", this.getClass().getClassLoader());
  Unmarshaller unmarshaller = context.createUnmarshaller();
  obj = unmarshaller.unmarshal(new StringReader(xml));
  </code></pre>
  
  <p>Anyone have some insight?</p>
  
  <p>EDIT: I tried the solution suggested by @abhin4v below (ie, add a space after <code>&amp;amp;</code>), but it doesn't seem to work too. Here's the stacktrace:</p>
  
  <pre><code>Caused by: org.xml.sax.SAXParseException: The entity name must immediately follow the '&amp;' in the entity reference.
          at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
          at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
          at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
          at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
          at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown Source)
          at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEntityReference(Unknown Source)
          at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
          at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
          at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
          at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
          at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
          at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
          at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
          at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:194)
  </code></pre>