Is it possible to force JAXB to marshall illegal characters in an XML tag?
===

I've got a database full of objects, along with user-defined properties. For example:

    class Media {
      String name;
      String duration;
      Map<String,String> custom_tags;
    }


    Media:
      Name: day_at_the_beach.mp4
      Length: 4:22
      Custom Tags:
        Videographer: Charles
        Owner ID #: 17a

Our users can come up with their own custom properties to attach to media, and fill in values accordingly. However, when I try to marshall the object into XML, I run into problems:

    <media>
      <name>day_at_the_beach.mp4</name>
      <length>4:22</length>
      <custom_tags>
        <Videographer>Charles</videographer>
        <Owner_ID_#>17a</Owner_ID_#>
      </custom_tags>
    </media>


`Owner_ID_#` is an illegal tag name in XML, because it contains a `#` so JAXB throws an `org.w3c.dom.DOMException: INVALID_CHARACTER_ERR: An invalid or illegal XML character is specified.` 

I know that the preferred, *correct* way to solve this problem would be to reformat the xml to something along the lines of:

    <custom_tags>
      <custom_tag>
        <name>Owner ID #</name>
        <value>17z</value>
      </custom_tag>
    </custom_tags>

 However, I'm *required* to return the former, invalid XML, to maintain legacy behavior from a previous, less-picky implementation of the code. Is there any way to tell JAXB not to worry about the illegal XML character, or am I going to be stuck doing a string replace before/after encoding? My current implementation is simply:


    public static <T> String toXml(Object o, Class<T> z) {
        try {
            StringWriter sw = new StringWriter();
            JAXBContext context = JAXBContext.newInstance(z);
            Marshaller marshaller = context.createMarshaller();
            marshaller.marshal(o, sw);
            return sw.toString();
        } catch (JAXBException e) {
            throw new RuntimeException(e);
        }
    }