开发者

XML in HTTP response

开发者 https://www.devze.com 2023-04-05 15:30 出处:网络
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

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>&lt;span style="color:blue;font:18pt" &gt;fevers&lt;/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.

0

精彩评论

暂无评论...
验证码 换一张
取 消