While I don't know your use case, it seems that you are trying to represent
XML document in string. Why not use XML library instead

On 17 Nov 2016 7:40 a.m., "Samuel Williams" <space.ship.traveller / gmail.com>
wrote:

> Right now, I'm using a set of wrapper classes... but it doesn't seem
> as elegant :)
>
> On 17 November 2016 at 15:09, Samuel Williams
> <space.ship.traveller / gmail.com> wrote:
> > Yeah, it would be awesome if I could make some encodings, e.g.
> > "UTF-8-XHTML" which is UTF-8 with XHTML entities. It would be then
> > possible to do something like:
> >
> >     "&amp;".force_encoding("UTF-8-XHTML") == "&"
> >
> > The reason why I like this approach is that conversion would be
> > handled automatically on output or manipulation. No conversion would
> > be required just for output, but stuff like RegExp would work as you
> > expect it to, in theory.
>
> Unsubscribe: <mailto:ruby-talk-request / ruby-lang.org?subject=unsubscribe>
> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
>
(supressed text/html)
Unsubscribe: <mailto:ruby-talk-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>