I have read about how to process XML and handle invalid text in element values; what I haven't been able to learn is: how do I ensure the text I _write_ as an XML element value is valid?

With VC++ 6.0, I'm reading text from an NTEXT database field and writing it with home-grown, text-based XML routines. (I'm not very familiar with DOM, but would be willing to work on it.)

Is there a way to pass the text thru some character encoding filter to ensure the ampersands (and all other special characters) get converted to & (and their corresponding &xxx; values) ?

Thanks for reading.