Display XML content in HTML page

前端 未结 5 1924
情书的邮戳
情书的邮戳 2020-11-27 05:38

How to display XML and other type of data in same page ?

    

    
        <         


        
5条回答
  •  庸人自扰
    2020-11-27 06:07

    If you treat the content as text, not HTML, then DOM operations should cause the data to be properly encoded. Here's how you'd do it in jQuery:

    $('#container').text(xmlString);
    

    Here's how you'd do it with standard DOM methods:

    document.getElementById('container')
            .appendChild(document.createTextNode(xmlString));
    

    If you're placing the XML inside of HTML through server-side scripting, there are bound to be encoding functions to allow you to do that (if you add what your server-side technology is, we can give you specific examples of how you'd do it).

提交回复
热议问题