static MCD_STR CMarkup::EscapeText( MCD_CSTR szText, int nFlags = 0 );

The EscapeText static utility function is used internally to escape the Standard Special Characters when inserting a text value into the document. You can use it to escape special characters when dealing with markup text directly.

The EscapeText function accepts optional flags which can be OR'd together. The MNF_ESCAPEQUOTES flag indicates that single and double quotes should be escaped (this is necessary in attribute values, but not in element data content). The MNF_WITHREFS flag indicates that the text may contain entity references such as escaped special characters and numeric character references for which the starting ampersand should not be escaped (see also MNF_WITHREFS in AddElem and SetData Flags). This is needed when you want " " in your XML instead of " ". For an example of EscapeText using both flags, we escape text containing an apostrophe, a less than sign and an encoded Chinese character for which we do not want the leading ampersand to be escaped.

CString csText = "Ben's < &#22269;";
int nFlags = CMarkup::MNF_ESCAPEQUOTES | CMarkup::MNF_WITHREFS;
CString csEscaped = CMarkup::EscapeText( csText, nFlags );
// csEscaped == "Ben&apos;s &lt; &#22269;"

See also the UnescapeText method.

The UnescapeText and EscapeText static utility functions replaced the protected internal x_TextFromDoc and x_TextToDoc functions in CMarkup release 8.0.