XML文本转义

This commit is contained in:
陈精华 2022-12-13 16:26:23 +08:00
parent cf336781d8
commit 3abcfe90bc
No known key found for this signature in database
GPG Key ID: 30BDC970902B755D
1 changed files with 16 additions and 0 deletions

View File

@ -46,8 +46,24 @@
/**
* 加载xml数据
*/
function htmlEscape(str){
var s = "";
if(str.length == 0) return "";
s = str.replace(/&/g,"&");
s = str.replace(/&/g,"&");
s = s.replace(/&lt;/g,"<");
s = s.replace(/&gt;/g,">");
s = s.replace(/&nbsp;/g," ");
s = s.replace(/&#39;/g,"\'");
s = s.replace(/&quot;/g,"\"");
s = s.replace(/<script.*?>.*?<\/script>/ig, '');
s = s.replace(/<script/gi, "&lt;script ");
s = s.replace(/<iframe/gi, "&lt;iframe ");
return s;
}
function loadXmlData() {
var textData = Base64.decode($("#textData").val())
textData = htmlEscape(textData);
window.textPreData = "<xmp style='background-color: #FFFFFF;overflow-y: scroll;border:none'>" + textData + "</xmp>";
var xmlNode = xmlTreeViewer.parseXML(textData);
window.retNode = xmlTreeViewer.getXMLViewerNode(xmlNode.xml);