Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

XML and CSS


May 27, 2021 XML


Table of contents


Use CSS to display XML

In this section, we'll show you anyone who displays XML through CSS.


By using CSS (Cascading Style Sheets Cascading Styles Styles Style Sheets), you can add display information to the XML document.


Show your XML using CSS?

It is possible to format XML documents using CSS.

The following example is about how to format an XML document using a CSS style sheet:

Look at this XML file: CD directory

Then look at this style sheet: CSS file

Finally, check out: Cd directories formatted with CSS files

Below is a small part of the XML file. The second line links the XML file to the CSS file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/css" href="cd_catalog.css"?>
<CATALOG>
<CD>
<TITLE>Empire Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
<PRICE>10.90</PRICE>
<YEAR>1985</YEAR>
</CD>
<CD>
<TITLE>Hide your heart</TITLE>
<ARTIST>Bonnie Tyler</ARTIST>
<COUNTRY>UK</COUNTRY>
<COMPANY>CBS Records</COMPANY>
<PRICE>9.90</PRICE>
<YEAR>1988</YEAR>
</CD>
.
.
.
</CATALOG>

Formatting XML with CSS is not a common method.

The W3C recommends XSLT, see the next chapter.


Related tutorials

CSS tutorial