title: Unmarshall XML with attribute containing CDATA using JAXB2 OXM
body: <p>I am trying to unmarshal an XML which looks like this:</p>
  
  <p>==============================[XML]====================================</p>
  
  <pre><code>&lt;Element1&gt;
  &lt;innerElement attr1="value1"&gt;
      &lt;ConcernedElement FirstAttribute="FirstValue" SecondAttribute="&lt;![CDATA[&lt;AttributeElement aAttribute="aValue" bAttribute="bValue"&gt;&lt;vElement vAttrib="aV.Value"&gt;&lt;/vElement&gt;&lt;/AttributeElement&gt;]]&gt;"&gt;&lt;/ConcernedElement&gt;
  &lt;/innerElement&gt;
  &lt;/Element1&gt;
  </code></pre>
  
  <p>The Schema Definition is as below:</p>
  
  <p>==============================[XSD]=================================</p>
  
  <p>
  </p>
  
  <pre><code>&lt;xs:element name="Element1"&gt;
      &lt;xs:complexType&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element ref="innerElement" minOccurs="0"/&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  
  &lt;xs:element name="innerElement"&gt;
      &lt;xs:complexType&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element ref="ConcernedElement" minOccurs="0"/&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  
  &lt;xs:element name="ConcernedElement"&gt;
      &lt;xs:complexType&gt;
          &lt;xs:attribute name="FirstAttribute" type="xs:string"/&gt;
          &lt;xs:attribute name="SecondAttribute" type="xs:string"/&gt;
      &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  </code></pre>
  
  <p></p>
  
  <p>Whenever I tried to do unmarshall with this function:</p>
  
  <pre><code>public Object unmarshall(String xml) {
      try {
          StringBuffer stringBuffer = new StringBuffer(xml);
          StringReader stringReader = new StringReader(stringBuffer.toString());
          StreamSource streamSource = new StreamSource(stringReader);
          Object object = customUnmarshaller.unmarshal(streamSource);
          return object;
  
      } catch (Exception ex) {
          return null;
      }
  }
  </code></pre>
  
  <p>I get an exception that <em>SecondAttribute</em> contains an invalid character &lt;.</p>
  
  <p>===================[EXCEPTION THROWN]======================</p>
  
  <pre><code>ex = (org.springframework.oxm.UnmarshallingFailureException) org.springframework.oxm.UnmarshallingFailureException: JAXB unmarshalling exception; nested exception is javax.xml.bind.UnmarshalException
   - with linked exception:
  [org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 159; The value of attribute "SecondAttribute" must not contain the '&lt;' character.]
  </code></pre>
  
  <p>Also, doing an XML Validation indicate that the XML is invalid.</p>
  
  <p>Is there something else I need to do or a config that I'm missing out?
  How do I resolve this?</p>