简体   繁体   中英

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>&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 itself 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

字符数据(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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM