JIYIK CN >

Current Location:Home > Learning > WEB FRONT-END > HTML >

Displaying XML in HTML

Author:JIYIK Last Updated:2025/04/19 Views:

This article describes how to display XML code on an HTML page.


Introduction to Extensible Markup Language (XML)

It is a markup language similar to HTML, but has no built-in tags. Instead, tags are created by the user as per the user's requirements.

It is an efficient way to store data in a structured manner that can later be quickly accessed, searched, and shared across different endpoints.

Best of all, because XML syntax is standardized, even if you start sharing or transferring XML across platforms or systems, either directly or over the Web, the recipients will still be able to parse the data.

Differences from HTML

It is somewhat similar to HTML as both use tags, but the difference is that XML does not have any predefined tags. Instead, all tags are made according to the needs and requirements of the users.

These tags have the appropriate data format to be transferred from one tag to another. Moreover, HTML is concerned with the appearance of the web page and enhances it, whereas XML is just a piece of information or data sent to someone.


Displaying XML code in HTML

Since XML also works with tags, displaying XML code on an HTML page is a challenge because it also manipulates the XML tags through the manipulation of HTML tags.

Therefore, if we need to display XML code on an HTML page, we can either enclose it <xmp>in tags or write it in <textarea>.

In both cases, the XML tags are not manipulated when the HTML page is rendered, but the entire code is displayed.

Use <xmp>the tag to display XML code on an HTML page

Sample code:

<h1> Example to display XML code in HTML </h1>
<xmp>
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <article>
        <data>
            <title>Test HTML page</title>
            <author>NSS</author>
            <country>Pakistan</country>
            <year>2022</year>
        </data>
    </article>
</xmp>

The HTML code above uses <xmp>the tag and contains our XML data in this tag. XML data contains some data. Each tag of XML is the name of the data kept in it.

Now, <xmp>the effect is that this XML code will be displayed as is, without interpretation. Note that we have also used HTML tags in the code to mark the difference between the two.

But the problem is that <xmp>the <head> tag is now deprecated after HTML 3.2. Hence, using it directly in the current HTML version is not advisable.

Use <textarea>the tag to display XML code on an HTML page

Another way to display XML code is to enclose it in <textarea>. <textarea>The same is true for . It will display any text within it as is without manipulating it.

We can specify the number of rows and columns to set <textarea>the size of the . Take a look at the following example where we use <textarea>to display XML on the screen in a preformatted style.

Sample code:

<h1> Example to display XML code in HTML </h1>
<textarea cols="35" rows="20" style="border:none;">
    <?xml version="1.0" encoding="ISO-8859-1"?>
<article>
    <data>
        <title>Test HTML page</title>
        <author>NSS</author>
        <country>Pakistan</country>
        <year>2022</year>
    </data>
</article>
</textarea>

We applied border: noneso that it hides the textbox and does not display it. Let's see its output.

So we can say that if we need to display any XML code as it is without rendering its markup on HTML page, we can use any of these two methods.

Previous: None

Next:Read-only checkbox in HTML

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

Creating a currency input in HTML

Publish Date:2025/04/19 Views:119 Category:HTML

In this article, users will learn to input convert a normal HTML field into a currency input field. We will use HTML and jQuery to achieve our goal. input Convert plain to currency input in HTML using JavaScript toFixed() method In HTML, th

HTML Hide Buttons and Show Them Using Onclick

Publish Date:2025/04/19 Views:178 Category:HTML

This article will show you several ways to hide HTML buttons and make them visible using the onclick event. Using the CSS display property to show hidden buttons in HTML We can first hide the HTML button by setting its display property to n

Right align button in HTML

Publish Date:2025/04/19 Views:136 Category:HTML

Alignment is the positioning of text or buttons in different places like right, left or center on an HTML web page. We can easily use the alignment properties to place our text, images or other elements anywhere on the web page. There may b

Readonly in HTML Select Tag

Publish Date:2025/04/19 Views:176 Category:HTML

TML, Hypertext Markup Language, is widely used to format websites. Also, CSS (Cascading Style Sheets) can be used to style websites. Below are some of the attributes used in HTML and CSS to control user and cursor behavior. select readonly

The role attribute in HTML

Publish Date:2025/04/19 Views:142 Category:HTML

In this article, we will introduce the HTML role attribute and its uses. Introduction to the role attribute in HTML The role attribute in HTML belongs to the WAI-ARIA (Web Accessibility Initiative - Accessible Rich Internet Applications) sp

Pagination when printing in HTML

Publish Date:2025/04/19 Views:147 Category:HTML

This article will introduce several ways to force page breaks when printing HTML content. Set the page-break-after property to always Inside @media print to Page Break in HTML The @media print rule of CSS lets us apply rules when printing H

Displaying Cookie-Based Images in HTML

Publish Date:2025/04/19 Views:95 Category:HTML

This article will introduce a method to display images in HTML format based on cookies set in PHP. Display images based on cookies set in HTML The problem statement is that we need to display a specific image based on a cookie passed by the

Creating a download link in HTML

Publish Date:2025/04/19 Views:158 Category:HTML

This article will introduce a method to create a download link in HTML. Use the download attribute to create download links in HTML We can create a download link using the download attribute inside the HTML anchor element. In the anchor tag

::before Selector in HTML

Publish Date:2025/04/19 Views:124 Category:HTML

This article will introduce CSS ::before pseudo-elements and explore their application in HTML. CSS ::before pseudo-element ::before The selector is a CSS pseudo-element that we can use to insert content before one or more selected elements

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial