title: Parse HTML/XML characters in R
body: <p>I am reading in the following XML as a text file in R:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;
  &lt;!DOCTYPE score-partwise PUBLIC
      &quot;-//Recordare//DTD MusicXML 3.0 Partwise//EN&quot;
      &quot;http://www.musicxml.org/dtds/partwise.dtd&quot;&gt;
  &lt;score-partwise version=&quot;3.0&quot;&gt;
    &lt;part-list&gt;
      &lt;score-part id=&quot;P1&quot;&gt;
        &lt;part-name&gt;Music&lt;/part-name&gt;
      &lt;/score-part&gt;
    &lt;/part-list&gt;
    &lt;part id=&quot;P1&quot;&gt;
      &lt;measure number=&quot;1&quot;&gt;
        &lt;attributes&gt;
          &lt;divisions&gt;1&lt;/divisions&gt;
          &lt;key&gt;
            &lt;fifths&gt;0&lt;/fifths&gt;
          &lt;/key&gt;
          &lt;time&gt;
            &lt;beats&gt;4&lt;/beats&gt;
            &lt;beat-type&gt;4&lt;/beat-type&gt;
          &lt;/time&gt;
          &lt;clef&gt;
            &lt;sign&gt;G&lt;/sign&gt;
            &lt;line&gt;2&lt;/line&gt;
          &lt;/clef&gt;
        &lt;/attributes&gt;
        &lt;note&gt;
          &lt;pitch&gt;
            &lt;step&gt;C&lt;/step&gt;
            &lt;octave&gt;4&lt;/octave&gt;
          &lt;/pitch&gt;
          &lt;duration&gt;4&lt;/duration&gt;
          &lt;type&gt;whole&lt;/type&gt;
        &lt;/note&gt;
      &lt;/measure&gt;
    &lt;/part&gt;
  &lt;/score-partwise&gt;
  </code></pre>
  <p>R:</p>
  <pre><code>library(readtext)
  
  xml &lt;- readtext(&quot;musicxml.txt&quot;)$text
  </code></pre>
  <p>I am then trying to render this in Javascript via Shiny by feeding my XML text to a Javascript function. NB: Working outside of R.</p>
  <pre><code>shiny::tags$script(paste0('var osmd = new opensheetmusicdisplay.OpenSheetMusicDisplay(\&quot;sheet-music\&quot;, {drawingParameters: &quot;compact&quot;,
                  drawPartNames: false, drawMeasureNumbers: false, drawMetronomeMarks: false, drawTitle: false});
                  var loadPromise = osmd.load(\'',xml,'\');
                                loadPromise.then(function(){
                                osmd.render();
                                });
                                '))
  </code></pre>
  <p>However, when I concatenate the XML string above, it does not work because characters are escaped, e.g one line:</p>
  <pre><code> &amp;lt;note&amp;gt;
  </code></pre>
  <p>I tried using the unescape_xml function <a href="https://stackoverflow.com/a/35187962">here</a> (with and without the  tags removed), but this does not solve the problem. It leaves me with:</p>
  <pre><code>&quot;Music1044G2C44whole&quot;
  </code></pre>
  <p>So how can I end up with a concatenated string with none of the escaped characters? It must just be a string and not another R object.</p>