Basically, what we are going to do in this tutorial is to show the data from XML:
into this:
The full tutorial is accessible by clicking "Read More" ->
1. FOLDER
Navigate to your xampp/htdocs folder. Create a new folder, rename it to anything you want. For example, I saved mine as 'cd'.
2. XML
Create the following XML file and save it in your 'cd' folder.
cdcat.xml
<?xml version="1.0" encoding="UTF-8"?> <CATALOG> <CD> <ART>album art/tapa smile.jpg</ART> <TITLE>Smile</TITLE> <ARTIST>L'Arc~en~Ciel</ARTIST> <COMPANY>Ki'ooh Records</COMPANY> <COUNTRY>Japan</COUNTRY> <PRICE>25.00</PRICE> <YEAR>2001</YEAR> </CD> <CD> <ART>album art/BGFROD.jpg</ART> <TITLE>Brutal Games for Reminding of Death</TITLE> <ARTIST>CROW'S CLAW</ARTIST> <COMPANY>Tora no Ana</COMPANY> <COUNTRY>Japan</COUNTRY> <PRICE>12.00</PRICE> <YEAR>2007</YEAR> </CD> <CD> <ART>album art/ORIGINAL INTENTION_01.jpg</ART> <TITLE>ORIGINAL INTENTION PLUS</TITLE> <ARTIST>CROW'S CLAW</ARTIST> <COMPANY>Tora no Ana</COMPANY> <COUNTRY>Japan</COUNTRY> <PRICE>20.00</PRICE> <YEAR>2012</YEAR> </CD> </CATALOG> |
<ART>album art/tapa smile.jpg</ART> |
The 'album art/tapa smile.jpg' is a string. 'album art/' is the folder name, and 'tapa smile' is the image filename. Create a folder named 'album art' in your folder. That is where we're going to upload the images as cd album cover later.
Save the following images into the 'album art' folder if you want to see something good.
3. XSL & CSS
Create an XSL file to format the XML file in a meaningful view. Save this XSL file into your 'cd' folder.
ALLCD.xsl
ALLCD.xsl
<?xml version="1.0" encoding="UTF-8"?> |
This XSL file has been formatted to read string value and change it into html readable format.
This part will enable formatting string into html:
|
This part reads the string and change it into html:
|
style.css
Copy the following code and save as 'style.css' in your cd folder:
body, h1, h2, th, td, tr, div {font-family: 'Oxygen', sans-serif; } |
4. PHP for browsing the XML by using the XSL format
Now, we'll use PHP to take both XML and XSL to produce the following result:
the sourcecode:
browsecd.php
the sourcecode:
browsecd.php
<?php $xsl = new DOMDocument; //loads the xslt file $xsl->load('ALLCD.xsl'); $proc = new XSLTProcessor; //attach xsl rules $proc->importStyleSheet($xsl); echo $proc->transformToXML($xml); // displaying XML data using XSLT |
Since we're using PHP, that means the PHP-enabled server must be switched on first. Open xampp and start apache server.
Then, on your browser, type "localhost/cd/browseCD.php" to view the result.
5. Create HTML form to add new data into your XML:
HTML
Addcd.html
Addcd.html
<html> |
Create a php that would do the dynamic scripting to your server:
addcditem.php
<?php |
Type 'localhost/cd/addcd.html' and you'll get the following form:
Finally, test to see your code works or not. Enjoy coding!
No comments:
Post a Comment