0

I have a XML which I parse and place in HTML, dynamically when asked for.

It has some line feed 
 which I want to replace with 
	, so it comes in proper readable format. For some reason 
 is not creating a LineFeed.

var lput=$(xml).find('lput_info').attr('output');

lput=lput.ReplaceAll("
", "
	");

'<table class="jpanelTable" >'+
    '<tbody>'+              
    '<tr width="100%">'+
        '<th class="thPanel">Output</th>'+
        '<td class="tdPanel"><pre class="preWrap">'+lput+'</pre></td>'+
    '</tr>'+                
    '</tbody>'+
'</table>'

Using this function from here:

String.prototype.ReplaceAll = function(stringToFind,stringToReplace){
    var temp = this;
    var index = temp.indexOf(stringToFind);
    while(index != -1){
        temp = temp.replace(stringToFind,stringToReplace);
        index = temp.indexOf(stringToFind);
    }
    return temp;
}

Update

.preWrap {
    overflow: auto;
    font-family: "Consolas",monospace;
    font-size: 9pt;
    text-align:left;
    background-color: #FCF7EC;
    overflow-x: auto; /* Use horizontal scroller if needed; for Firefox 2, not
    white-space: pre-wrap; /* css-3 */
    white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */
    word-wrap: break-word; /* Internet Explorer 5.5+ */
    margin: 0px 0px 0px 0px;
    padding:5px 5px 3px 5px;
    white-space : normal; /* crucial for IE 6, maybe 7? */
}

Part of the xml input string:

"bpmz.a&#xa;/usr/lib/libdl.a(shr_64.o)&#xa;/usr/lib/libperfstat.a(shr_64.o)&#xa;/usr/lib/lib.a"
4

1 回答 1

1

有些人可能会建议一个(jQuery)函数创建一个临时div的,将文本放在那里,然后获取 , 的内容div来解码字符串。

尽管它的实现很简单,但它相当不安全,因为您几乎会要求用户在字符串中放置各种 html 标签。

我建议使用这些功能
需要第二个功能

这些比div替代方案更安全。

于 2012-12-05T07:40:56.987 回答