HTML tags in XML
How do I construct a valid X开发者_C百科ML string from keys/values when values may contain html tags. As far as I know html tags are not allowed in XML, right? Then the question is, how do I properly escape them?
use CDATA block like
<xml><![CDATA[
<html>
line 1<br>
line 2
</html>
]]>
</xml>
You have to differentiate between HTML and XHTML. While HTML allows unclosed elements (e.g. <br>) XHTML doesn't (here <br/>). So XHTML is valid XML and HTML isn't. To insert HTML you need to use CDATA as mentioned by lweller, but wellformed XHTML (even XHTML5) can just be inserted without any escaping. If the file comes without DTD, you only have to be sure not to use element-names that are reserved for XHTML. Using DTD and Namespaces makes it more complicated.
Try replacing <
by <
and >
by >
, it's a bit ugly but might work
精彩评论