How do i display xml content in html?

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

    

    
        Empire Burlesque
        Bob Dylan
        USA
        Columbia
        10.90
        1985
    

The above XML should be displayed as it is with formatting. Also , I would like to display HTML tables and other stuff in my page. How to achieve this ?

  1. I do get XML in STRING not through file.
  2. I do not want to parse it
  3. I want to display [that's it]
  4. If you say about XSLT [ please give example ]
  5. I'm thinking to use Jquery plugin [ any examples?]

asked Sep 22, 2011 at 18:26

Simple solution is to embed inside of a 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: //jsfiddle.net/y9fqf/1/

answered Sep 22, 2011 at 18:29

mellamokbmellamokb

55.4k12 gold badges106 silver badges135 bronze badges

4

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



your code/tables


    
        
            Empire Burlesque
            Bob Dylan
            USA
            Columbia
            10.90
            1985
        
    

Output:

your code/tables

    
        Empire Burlesque
        Bob Dylan
        USA
        Columbia
        10.90
        1985
    

answered Jul 13, 2014 at 13:47

KeombreKeombre

6055 silver badges11 bronze badges

1

answered Feb 26, 2016 at 9:45

mcsekarmcsekar

3862 silver badges13 bronze badges

2

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].

answered Sep 22, 2011 at 18:32

JacobJacob

76.1k23 gold badges146 silver badges225 bronze badges

5

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.

answered Jun 1, 2017 at 14:01

mkirouacmkirouac

1131 silver badge12 bronze badges

A simple solution for displaying XML data on an HTML page is that: go the this website

Paste your code and generate the XML code which you can use in pre-tag in HTML

to display.

answered Aug 4, 2021 at 18:56

How do you present XML in HTML?

Since XML tags are "invented" by the author of the XML document, browsers do not know if a tag like describes an HTML table or a dining table. Without any information about how to display the data, the browsers can just display the XML document as it is. Tip: If you want to style an XML document, use XSLT.

How do I display an XML file?

If all you need to do is view the data in an XML file, you're in luck. Just about every browser can open an XML file. In Chrome, just open a new tab and drag the XML file over. Alternatively, right click on the XML file and hover over "Open with" then click "Chrome".

How a XML document can be displayed on a browser?

XML files can be opened in the browser by just double-clicking the XML document [if it is a local file] or by typing the URL path in the address bar [if the file is located on the server], in the same way as we open other files in the browser. XML files are saved with a ". xml" extension.

Chủ Đề