How to print pretty xml in javascript?
问题 What's the best way to pretty-print xml in JavaScript? I obtain xml content through ajax call and before displaying this request in textarea i want to format it so it looks nice to the eye :) 回答1: This does not take care of any indenting, but helps to encode the XML for use within <pre> or <textarea> tags: /* hack to encode HTML entities */ var d = document.createElement('div'); var t = document.createTextNode(myXml); d.appendChild(t); document.write('<pre>' + d.innerHTML + '</pre>'); And if,