0

I need to pass a <![cdata[something-html-formatted]]> to a xml file where I parse it as a html email body. All is working except retrieving correctly the email body. Say, for instance, I have a string like this:

<![CDATA[I need to write <b>this</b> text in <i>italic</i>]]>

I always get the result on the email like this:

this</b> text in italic</i>]]>

How can I pass the complete string to the XML file?

Thanks in advance!

2
  • how are you generating the cdata in the xml file? also note that as a general rule, whatever your problem is, cdata is not the solution. Commented Jan 24, 2013 at 18:26
  • What are you using to send the email. Check format of your email. Is it marked as "HTML" format? Commented Jan 24, 2013 at 18:27

1 Answer 1

3

Simply encode it, like you would everything else, by replacing < with &lt; and > with &gt;:

<xml>
&lt;![CDATA[I need to write &lt;b&gt;this&lt;/b&gt; text in 
&lt;i&gt;italic&lt;/i&gt;]]&gt;
</xml>

works fine.

Sign up to request clarification or add additional context in comments.

1 Comment

The only situation where > needs to be escaped is the closing of a CDATA tag when serializing XML. You found an edge case. Its safe to always escape/unescape > though some frameworks do not do this for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.