title: Encoding Error in XML UTF-8 output
body: <p>I am generating a UTF-8 XML using Spring Data REST. I am annotating the method which returns the XML as follows:</p>
  
  <pre><code> @RequestMapping(value = "/Something/{id:.+}",
         method = RequestMethod.GET,
         produces = "application/xml")
  public @ResponseBody String metsResource(@PathVariable String id){...}
  </code></pre>
  
  <p>My program generates an XML with some data from various APIs. I am noticing in some of the APIs, the data has a copyright symbol. When I create my XML and check it out, it is generated fine But the browsers(tried with Chrome &amp; Safari) cannot render the XML. I get the following error. When I copied the XML output form the console, I could see the error position was right near the copyright symbol. I am not sure what went wrong in my XML, when the input contains a copyright symbol. Could anyone suggest a fix?</p>
  
  <p><img src="https://i.stack.imgur.com/dw3FM.png" alt="Browser Returned Error"></p>
  
  <p>--EDIT--</p>
  
  <p>Here is a chunk of the XML. If you see inside the element accessCondition, you will notice a copyright symbol. This is exactly where the browser stops rendering.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" standalone="no"?&gt;
  &lt;data&gt;
  &lt;hdr CREATEDATE="2014-07-21T12:40:09"/&gt;
  &lt;sec ID="123456"&gt;
   &lt;xmlData&gt;
     &lt;titleInfo&gt;
      &lt;title script="Latn"&gt;A book&lt;/title&gt;
      &lt;subTitle&gt;Indian stories&lt;/subTitle&gt;
     &lt;/titleInfo&gt;
     &lt;name&gt;
      &lt;namePart&gt;Jane Doe&lt;/namePart&gt;
      &lt;role&gt;Creator&lt;/role&gt;
     &lt;/name&gt;
     &lt;originInfo&gt;
      &lt;publisher script="Latn"&gt; ABCD Press&lt;/publisher&gt;
      &lt;place&gt; Connecticut&lt;/place&gt;
      &lt;dateOther encoding="w3cdtf" keyDate="yes"&gt;2009&lt;/dateOther&gt;
     &lt;/originInfo&gt;
     &lt;language&gt;
      &lt;languageTerm type="code"&gt;eng&lt;/languageTerm&gt;
      &lt;languageTerm type="text"&gt;English&lt;/languageTerm&gt;
     &lt;/language&gt;
     &lt;abstract&gt;A book with lot of Red Indian Stories.&lt;/abstract&gt;
     &lt;identifier type="hdl"&gt;123456&lt;/identifier&gt;
     &lt;location&gt;
      &lt;physicalLocation&gt;N7433.4 L44 A88 2009&lt;/physicalLocation&gt;
     &lt;/location&gt;
     &lt;accessCondition type="rightsOwnership"&gt;© 2009 Jane Doe - ABCD Press, Connecticut&lt;/accessCondition&gt;
     &lt;recordInfo&gt;Test&lt;/recordInfo&gt;
    &lt;/xmlData&gt;
   &lt;/sec&gt;
  &lt;/data&gt;   
  </code></pre>
  
  <p>The codebase which generates the complete XML is huge, so its hard to show here. But just before returning the XML, the program converts the ByteArrayOutputStream (variable 'out' in this case) into UTF-8</p>
  
  <pre><code>String xml = out.toString("UTF-8");
  </code></pre>
  
  <p>Like Jim Garrison suggested in the comments it seems like the © symbol in the input came in as ISO-8859-1 encoding. Reason: when I changed the above conversion of the ByteArrayOutputStream as following, the XML started to show.      </p>
  
  <pre><code>String xml = out.toString("ISO-8859-1"); 
  </code></pre>
  
  <p>Is there any way to get the output as UTF-8? Thank a lot!</p>