简体   繁体   English

使用JavaScript解码SecurityElement.Escape的正确方法

[英]Proper way to decode SecurityElement.Escape using Javascript

I've tried several methods to decode encoded xml using javascript. 我尝试了几种使用JavaScript解码编码的xml的方法。 For some reason all of them ignore ' which causes it to fail. 由于某种原因,他们所有人都忽略了',这导致它失败。 I can do a string.replace to fix the issue, but wondering why this happens or if there is some other method I should be using. 我可以执行string.replace来解决此问题,但想知道为什么会发生这种情况,或者是否应该使用其他方法。

I've tried decodeURIComponent as well as another method I found on SO that puts the content in a div and then pulls it back out. 我试过了解码URIComponent以及在SO上找到的另一种方法,该方法将内容放入div中,然后将其拉回。 Both ignore the '. 两者都忽略'。 I also tried unescape which curiously did nothing whatsoever. 我也尝试过unescape,奇怪的是什么也没做。 It is an xml block I am decoding. 这是我正在解码的xml块。

This is the only way I could find to do it since no one responded: 因为没有人回应,所以这是我唯一可以找到的方法:

function HtmlDecode(input) { var e = document.createElement('div'); 函数HtmlDecode(input){var e = document.createElement('div'); e.innerHTML = input; e.innerHTML =输入; return e.childNodes.length === 0 ? 返回e.childNodes.length === 0? "" : e.childNodes[0].nodeValue.replace(/'/g, "'"); “”:e.childNodes [0] .nodeValue.replace(/'/ g,“'”);
} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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