XML in HTTP response
I want to return some HTML code in my XML response. So it will be highlighted on the client side. so for example i have XML response like this
<Response id="1234"> <Document> <text><span style="color:blue;font:18pt" >fevers</span gt;</text></Document>
</Response>
The problem that the client understands this as "<span>fever</span>
" but not understanding the span its开发者_StackOverflow社区elf and highlighting the word "fever". and of course i can't send "<>" in XML as the library translates them directly to their codes. Any help would be appreciated Thank you
Enclose it with Character Data (CDATA):
<![CDATA[<hello>World!</hello>]]>
Base 64 encode it and you'll be able to send that XML - without having to deal with a CDATA section on the client side.
Personally, I don't think it's a good idea for servers to know anything about how data is rendered on the client side. Why should the server enforce what amounts to CSS style? That's a client issue.
If it must be enforced, make it a governance or communication issue; don't try to do it in code.
精彩评论