Why should you use XML CDATA blocks?

前端 未结 2 937
借酒劲吻你
借酒劲吻你 2021-01-19 13:31

When creating XML I\'m wondering why the CDATA blocks are uses rather than just escaping the data. Is there something allowed in a CDATA block that can\'t be escaped and pla

2条回答
  •  青春惊慌失措
    2021-01-19 13:46

    CDATA is just the standard way of keeping the original text as is, meaning that whatever application processes the XML shouldn't need to take any explicit action to unescape.

    You get that typically with JavaScript embedded in XHTML, when you use reserved symbols:

    
    

    If you had if (1 > 0) instead, it would have to unescape explicitly (which it doesn't). It's also much more readable like this.

提交回复
热议问题