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"
2
  • Haven't you answered your own question with that ReplaceAll() function? Your code seems to work here: jsfiddle.net/DRKSk so perhaps the input string doesn't contain quite what you think it does. What does console.log(lput) show you? Please be a bit clearer about what the problem is. Commented Dec 5, 2012 at 7:33
  • @nnnnnn: Somehow the input from xml is not displaying with proper lineFeeds. In console.log I cannot see the it either Commented Dec 5, 2012 at 8:40

1 Answer 1

1

Some people might suggest a (jQuery) function that creates a temporary div, places the text in there, then gets the content of the div, to decode the string.

Although the implementation of it is simple, it is rather unsafe, since you'd pretty much be asking for users to put all kinds of html tags in the string.

I'd suggest using these functions
(Requires a second function)

These are safer than the div alternative.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.