title: How to clean a form field for an XML Attribute that will contain valid UTF8 characters?
body: <p>I have been struggling with this for a little while. I have a multi-lingual web app that outputs XML at some point. This XML can contain any language so my approach to sanitization has been to disallow certain characters that break XML from being inserted. That and wrapping as much as I can in CDATA, but I have a ton of content in the attributes. I don't want to disallow special characters because completely valid characters like parenthesis, periods, dashes, ticks and apostrophes are used all the time and they work.</p>
  
  <p>What is the best way to strip out all characters that will break a XML attribute, but leave languages intact?</p>
  
  <p><strong>UPDATE:</strong><br>
  I found: <a href="http://en.wikipedia.org/wiki/CDATA#CDATA-type_attribute_value" rel="noreferrer">http://en.wikipedia.org/wiki/CDATA#CDATA-type_attribute_value</a> , which indicated to me that I can describe an attribute as a CDATA section using DTD; however, this is not true it seems.</p>
  
  <pre><code>&lt;?xml version="1.0" ?&gt; 
  &lt;!DOCTYPE foo [
    &lt;!ELEMENT foo EMPTY&gt;
    &lt;!ATTLIST foo a CDATA #REQUIRED&gt;
  ]&gt;
  &lt;foo a="&amp;bull;"&gt;&lt;![CDATA[ &amp;bull; ]]&gt; &lt;/foo&gt;
  </code></pre>
  
  <p>Any validator will complain about bull not being an entity in the attribute. If you remove the attribute it will be valid. Also I hear schemas are the way to go, so if something like the above is possible but using an XML Schema instead, that would be awesome.</p>
  
  <p>Thanks!</p>