title: encode and decode bytes in xml strings
body: <p>I'm looking for a way to write and read byte data in xml files. I'd like the xml files to be human readable, so I'd like to avoid base64 encoding or anything similar. I figured I could do something like this. If I have a string <code>b'abc &lt; ABC\x04&amp;'</code> that needs to go into a tag <code>&lt;node&gt;</code>, then I'd write that as</p>
  
  <pre><code>&lt;node&gt;abc &amp;lt; ABC&amp;#x04;&amp;amp;&lt;/node&gt;
  </code></pre>
  
  <p>Is there a way to make this kind of encoding work with any xml library in python3? I'd prefer <code>lxml</code>, but that's not a requirement.</p>
  
  <p><strong>Clarification</strong>: When I write an xml file, the strings are initially of type <code>bytes</code>, e.g. <code>b'abc &lt; ABC\x04&amp;'</code>. In a lot of cases they only contain alphanumeric ascii characters, which I want written to xml as such. Other bytes I want to encode as hex values, so they can still be easily understood. And I'd like to encode characters like <code>&gt;</code> and <code>&amp;</code> as <code>&amp;gt;</code> and <code>&amp;amp;</code> (or else also as hex values) to avoid using <code>&lt;![CDATA[&lt;]]&gt;</code>. When I read the strings, I'd like them to be converted back to <code>b'...'</code>, if possible.</p>