Home >>XML Tutorial >XML CSS

XML CSS

XML CSS

Purpose of CSS in XML

CSS (Cascading Style Sheets) may be used to add style to an XML document and show the information. This will format the whole Document XML.

How to link XML file with CSS

To link XML files with CSS, you should use the following syntax:

<?xml-stylesheet type="text/css" href="style.css"?>

XML CSS Example

style.css


employee  
{  
background-color: blue;  
}  
firstname,lastname,email  
{  
font-size:18px;  
display:block;  
color: white;  
margin-left: 30px;  
}   

Let's create the DTD file.

employee.dtd


<!ELEMENT employee (firstname,lastname,email)>  
<!ELEMENT firstname (#PCDATA)>  
<!ELEMENT lastname (#PCDATA)>  
<!ELEMENT email (#PCDATA)>  

Let's see the xml file using CSS and DTD.

employee.xml


<?xml version="1.0"?>  
<?xml-stylesheet type="text/css" href="cssemployee.css"?>  
<!DOCTYPE employee SYSTEM "employee.dtd">  
<employee>  
  <firstname>phptpoint</firstname>  
  <lastname>Noida</lastname>  
  <email>[email protected]</email>  
</employee>