Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


Basic Techniques - Page 20

November 18, 2002

Enough talk! It's time to see these server-side languages in action. We'll now go through some basic XML processing techniques, with examples from each language. This section should give you a good basic arsenal for tackling the most common XML tasks.

We'll create a simple web application for organizing our CD collection. We'll store the name of the artist, the name of the CD, and the year it was released. The list of CDs will be stored in an XML document. We need to be able to add new CDs to the list, modify existing ones, and also remove CDs from the list. We also want to display the list in HTML format, so we need to be able to transform the XML document to HTML.

The files that we'll create are the following:

cd_list.xml

The XML document containing the list of CDs.

cd_list.xsl

The XSL stylesheet that transforms the CD list to HTML.

cd_list.(asp/php/jsp)

The page that transforms cd_list.xml using cd_list.xsl and outputs the result.

cd_edit.(asp/php/jsp)

The page that allows the user to input/modify information about a specific CD.

cd_save.(asp/php/jsp)

The page that saves the information that was input in cd_edit.(asp/php/jsp).

cd_delete.(asp/php/jsp)

The page that deletes a specific CD from the cd_list.xml.

The XML Document

The XML document that contains the CD list is very simple. Each <cd> element contains three elements: <name>, <band>, and <year>. Following is an example instance (cd_list.xml in the code download):

<?xml version="1.0" encoding="UTF-8"?>

<cd-list>

<cd id="1">

<name>Kid A</name>

<band>Radiohead</band>

<year>2000</year>

</cd>

<cd id="2">

<name>OK Computer</name>

<band>Radiohead</band>

<year>1997</year>

</cd>

<cd id="3">

<name>Felt Mountain</name>

<band>Goldfrapp</band>

<year>2001</year>


</cd>

<cd id="4">

<name>Tourist</name>

<band>St. Germain</band>

<year>2000</year>

</cd>

<cd id="5">

<name>The Private Press</name>

<band>DJ Shadow</band>

<year>2002</year>

</cd>

<cd id="6">

<name>Protection</name>

<band>Massive Attack</band>

<year>1994</year>

</cd>

</cd-list>

Note that each <cd> element has a unique id. We'll put this id in the query string to send it between pages, to identify which CD we are currently working with. For those of you who don't know, the query string is the part after the "?" in the URL. We can send variables using the syntax "name=value", and separate multiple name/value pairs with "&". For example http://myserver.com/mypage.html?param1=value1&param2=value2.

JSP - Page 19
Practical XML for the Web
Transforming the XML - Page 21


Up to => Home / Authoring / Languages / XML / PracticalXML




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers