How we use CSS with XML?

How we use CSS with XML?

 Using CSS(Cascading Style Sheet) we can display our XML document with attractive display.I have given you a example how to add CSS property with XML.

Example:

An example of XML document.

- <bookstore>

- <book>

  <category>JAVA</category> 

  <title>The Complete Reference</title> 

  <author>Herbert Schildt</author> 

  <year>2005</year> 

  <price>30.91</price> 

  </book>

- <book>

  <category>C++</category> 

  <title>Programming in ANSI C++</title> 

  <author>E Balaguruswamy</author> 

  <year>2007</year> 

  <price>38.99</price> 

  </book>

- <book>

  <category>C</category> 

  <title>Exploring C</title> 

  <author>Yashwant kanetkar</author> 

  <year>2006</year> 

  <price>42.95</price> 

  </book>

  </bookstore>

we create a CSS for above example.

bookstore

{

background-color: #ffffff;

width: 100%;

}

book

{

display: block;

margin-bottom: 30pt;

margin-left: 0;

}

category

{

color: #FF0000;

font-size: 20pt;

}

title

{

color: #0000FF;

font-size: 20pt;

}

author,year,price

{

display: block;

color: #000000;

margin-left: 20pt;

}


When we write our XML document with CSS

<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>

<!-- Edited by XMLSpy� -->

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


<bookstore>

    <book>

      <category>JAVA</category>

      <title>The Complete Reference </title> 

      <author>Herbert Schildt</author>     

      <year>2005</year>

      <price>30.91</price>

   </book>

   <book>

      <category>C++</category>  

      <title>Programming in ANSI C++</title>   

      <author>E Balaguruswamy</author>    

      <year>2007</year>   

      <price>38.99</price> 

   </book>

   <book>

      <category>C</category>  

      <title>Exploring C</title>   

      <author>Yashwant kanetkar</author>   

      <year>2006</year>   

      <price>42.95</price> 

   </book>

</bookstore> 


output:

JAVA The Complete Reference 

Herbert Schildt

 

2005

 

30.91

 

C++ Programming in ANSI C++ 

E Balaguruswamy

 

2007

 

38.99

 

C Exploring C 

Yashwant kanetkar

 

2006

 

42.95



By:Vivek
Date:2015-01-09 00:00:00

Post Your Answers


User Email:

User Name:
Answers:

Related XML Subjective Links

XML Subjective interview questions and answers for experienced and fresher