Display XML content in HTML page

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

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

    

    
        <         


        
相关标签:
5条回答
  • 2020-11-27 05:50

    2017 Update I guess. textarea worked fine for me using Spring, Bootstrap and a bunch of other things. Got the SOAP payload stored in a DB, read by Spring and push via Spring-MVC. xmp didn't work at all.

    0 讨论(0)
  • 2020-11-27 05:55

    Simple solution is to embed inside of a <textarea> element, which will preserve both the formatting and the angle brackets. I have also removed the border with style="border:none;" which makes the textarea invisible.

    Here is a sample: http://jsfiddle.net/y9fqf/1/

    0 讨论(0)
  • 2020-11-27 06:01

    You can use the old <xmp> tag. I don't know about browser support, but it should still work.

    <HTML>
    
    your code/tables
    
    <xmp>
        <catalog>
            <cd>
                <title>Empire Burlesque</title>
                <artist>Bob Dylan</artist>
                <country>USA</country>
                <country>Columbia</country>
                <price>10.90</price>
                <year>1985</year>
            </cd>
        </catalog>
    </xmp>
    

    Output:

    your code/tables
    <catalog>
        <cd>
            <title>Empire Burlesque</title>
            <artist>Bob Dylan</artist>
            <country>USA</country>
            <country>Columbia</country>
            <price>10.90</price>
            <year>1985</year>
        </cd>
    </catalog>
    
    0 讨论(0)
  • 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).

    0 讨论(0)
  • 2020-11-27 06:16
    <pre lang="xml" >{{xmlString}}</pre>
    

    This worked for me. Thanks to http://www.codeproject.com/Answers/998872/Display-XML-in-HTML-Div#answer1

    0 讨论(0)
提交回复
热议问题