Internet Systems Design:
Technologies for Modern Information Systems

Example XML Code

 

1. XML Example

<?xml version="1.0"?>

<XML ID="XMLID">

	<class>

		<student ID="0001"> 

			<name>Jessica</name> 

  			<email>jessica@blue.weeg.uiowa.edu</email> 

  		</student>

	

 		<student ID="0002"> 

			<name>Peter</name> 

  			<email>peter@icaen.uiowa.edu</email> 

  		</student>

 

 		<student ID="0003"> 

			<name>Alen</name> 

  			<email>alen@yahoo.com</email> 

  		</student>

  	</class>

</XML>

The result can be viewed at http://www.engineering.uiowa.edu/~ie181/XML/myxml.xml

 

2. CSS Example

class	{	display: block;

		border: 2px solid black;

		padding: 1em;

		background-color: #888833;

		color: #FFFFDD;

		font-family: Times, serif;

		font-style: italic;

		text-align: center;

			}

student	{	display: block;

		border: 2px solid black;

		padding: 1em;

		background-color: #008833;

		color: #FFFFFF;

		font-family: Times, serif;

		font-style: italic;

		text-align: center;	

			}

name	{       display: block;

		border: 0px solid black;

		padding: 1em;

		background-color: #008833;

		color: #FFDDAA;

		font-family: Times, serif;

		font-style: italic;

		text-align: center;			

			}

email	{display: block;}

This CSS file can be viewed at www.engineering.uiowa.edu/~ie181/XML/mycssadv.css You can open it with notepad, another text editor or a CSS editor

NOTE: In order to use this CSS file to present your XML data, you need to:
(1) Save the file as a .css file and put it in the same folder as your XML file (or amend the URL below).
(2) Add <?xml-stylesheet type="text/css" href="cssfilename.css" ?> to your XML file below your <?xml version="1.0"?> statement:

In this case the XML file used is Example 1 above. The result can be viewed at:
http://www.engineering.uiowa.edu/~ie181/XML/myxmlcssadv.xml. Note that if you view the source you can see the code for Example 1 as above but with the addition of the CSS reference.

3. XSL Example

<?xml version="1.0" ?> 

 <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">

 <xsl:template match="/">

 <HTML>

 <BODY>

 <TABLE BORDER="2">

 <TR>

  <TD>Name</TD> 

  <TD>E-mail Address</TD> 

 </TR>

 

<xsl:for-each select="XML/class/student">

 <TR>

   <TD>

      <xsl:value-of select="name" /> 

   </TD>

   <TD>

      <xsl:value-of select="email" /> 

   </TD>

  </TR>

  </xsl:for-each>

 </TABLE>

 </BODY>

 </HTML>

</xsl:template>

</xsl:stylesheet>

This file can be viewed at  http://www.engineering.uiowa.edu/~ie181/XML/myxsl.xsl

NOTE: In order to use this XSL file to present your XML data, you need to:
(1) Save the file as a .xsl file and put it in the same folder as your XML file (or amend the URL below)
(2) ADD <?xml-stylesheet type="text/xsl" href="my_xsl_file_name.xsl" ?> to your XML file below your <?xml version="1.0"?> statement:

The results can be viewed at: http://www.engineering.uiowa.edu/~ie181/XML/myxmlxsl.xml

4. Use XSL to sort your XML data

Modify the line of your XSL file:
<xsl:for-each select="XML/class/student">
Into:
<xsl:for-each select="XML/class/student" order-by="email">

This XSL file can be viewed at http://www.engineering.uiowa.edu/~ie181/XML/myxslwithsort.xsl

Change the XML file to reference this new XSL file.

Load your XML file again to see what happens...

The results can be viewed at: http://www.engineering.uiowa.edu/~ie181/XML/myxmlxslwithsort.xml

Use View Source to examine the XML file.