aspose file tools*
The moose likes XML and Related Technologies and the fly likes Sample XML programs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Sample XML programs" Watch "Sample XML programs" New topic
Author

Sample XML programs

megala, megala
Greenhorn

Joined: Aug 17, 2001
Posts: 1
i want to learn XML.so kindly help me to know about how to compile and run XML programs. and i want some simple XML examples
Paramagurusamy Balasubramanian
Ranch Hand

Joined: Aug 17, 2001
Posts: 55
Hi megala,
Try this example
/*** samp2.xml **/
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="samp2.xsl"?>
<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>Return of the Judai</TITLE>
<ARTIST>Judas Priest</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
<PRICE>20.90</PRICE>
<YEAR>1995</YEAR>
</CD>
<CD>
<TITLE>Dangerous</TITLE>
<ARTIST>Michael Jackson</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Sony</COMPANY>
<PRICE>30.00</PRICE>
<YEAR>1992</YEAR>
</CD>
</CATALOG>
/****samp2.xsl ****/
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
<body>
<table border="2" bgcolor="cyan">
<tr>
<th>Title</th>
<th>Artist</th>
<th>Price</th>
<th>Company</th>
</tr>
<xsl:for-each select="CATALOG/CD">
<tr>
<td><xsl:value-of select="TITLE"/></td>
<td><xsl:value-of select="ARTIST"/></td>
<td><xsl:value-of select="PRICE"/></td>
<td><xsl:value-of select="COMPANY"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet><?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
<body>
<table border="2" bgcolor="cyan">
<tr>
<th>Title</th>
<th>Artist</th>
<th>Price</th>
<th>Company</th>
</tr>
<xsl:for-each select="CATALOG/CD">
<tr>
<td><xsl:value-of select="TITLE"/></td>
<td><xsl:value-of select="ARTIST"/></td>
<td><xsl:value-of select="PRICE"/></td>
<td><xsl:value-of select="COMPANY"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
copy these 2 files in a directory..And call samp2.xml file in a browser..u will get the following in a table format..
Title Artist Price Company
Empire Burlesque Bob Dylan 10.90 Columbia
Return of the Judai Judas Priest 20.90 Columbia
Dangerous Michael Jackson 30.00 Sony
welcome to xml and All the best in learning...
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

XML is a technology to specify and render data. Its NOT
a traditional computer language like C/C++/Java/...
that you write programs and compile to see results
(atleast not in that sense).
Its more of a "how to represent this data?" and a lot more...
regds.
- satya

Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sample XML programs