Presentation is loading. Please wait.

Presentation is loading. Please wait.

XML & RDBMS By Molly Gumpert for: LIS 469: XML Fall 2014 Professor Gerry Benoit.

Similar presentations


Presentation on theme: "XML & RDBMS By Molly Gumpert for: LIS 469: XML Fall 2014 Professor Gerry Benoit."— Presentation transcript:

1 XML & RDBMS By Molly Gumpert for: LIS 469: XML Fall 2014 Professor Gerry Benoit

2 Uses  Relational databases allow for easy data storage, manipulation, and visualization and, when make correctly, help avoid errors.  xml files are a good way to make your DB data more interoperable with other systems  Though it can take a be time consuming to produce, once you have a working php script you can turn create xml files of your database data almost instantly.  These xml files are easily updatable when data is added, removed or updated in the database  In turn, websites created with these xml files are immediately updated with changes to the database without having to edit your other scripts

3 Client/Server Architecture Database User Server User interacts through an html form Form runs php script that connects to and queries database Result set outputted as a new xml file Xml file meets with existing xsl, css, and image files Formatted and styled xml file sent back to user’s browser Xml file

4 Example I began with a relational mySQL database designed and built during LIS458. The database serves a fictional art gallery and includes tables for artist information, art pieces, sales, deliveries and more.

5 html and php The “View Works” buttons under each artist on the Artist webpage link to three different php files.Artist webpage The php files are identical in every way except the WHERE statement in the sql query. Each artist is identified by a different “art_id” field $q = "SELECT w.work_id, w.title, w.series, w.medium, w.available, w.price, w.height, w.width, w.image_link FROM works AS w INNER JOIN collections AS c on w.work_id=c.work_id INNER JOIN artists on artists.art_id=c.art_id WHERE artists.art_id='1'";

6 php script <?php require ('mysqli_connect.php'); $q = "SELECT w.work_id, w.title, w.series, w.medium, w.available, w.price, w.height, w.width, w.image_link FROM works AS w INNER JOIN collections AS c on w.work_id=c.work_id INNER JOIN artists on artists.art_id=c.art_id WHERE artists.art_id='1'"; $r = @mysqli_query ($dbc, $q); if ($r) { $body = " "; while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { $body.=” ". $row['work_id']. " ". $row['title']. " ". $row['series']. " ". $row['medium']. " ". $row['available']. " ". $row['price']. " ". $row['height']. " ". $row['width']. " ". $row['image_link']. " "; } } else {print ' Error retrieving results '; $body.=" "; $resultfile = fopen('resultfile.xml', 'w+'); fwrite ($resultfile, $body); header( 'Location:resultfile.xml' ); mysqli_close($dbc);?> Opens and creates new xml file with the contents specified by $body variable Redirects browser to open new xml file Closes database connection Check for errors (truncated here for space) Creating the $body variable by writing tags, calling the sql results that will populate those tags Connect to DB (external script is reusable) Sql query joins three tables to find data on all the artworks by a specified artist Variable $r consists of database connection and sql query If both are correct, the if statement will run Writing the xml declaration and root tag and connecting the existing xsl file While statement runs through all the databse records called by the sql query and creates an associative array

7 resultfile.xml Without a connected stylesheet the php will output and redirect to a plain xml file. The same xml file “resultfile.xml” is rewritten everytime the script is run. This means any changes to the database will be reflected in the xml without any other changes elsewhere $resultfile = fopen('resultfile.xml', ’w'); fwrite ($resultfile, $body); header( 'Location:resultfile.xml' );

8 catalog.xsl* Series cm h x cm w $ No longer available for purchase The xsl file follows the Xpath structure to find certain tags and displays the data inside as directed. Tags allow for conditionals. Here works that are still available for purchase get special treatment. Creating an “img” element with a “src” attribute creates an html string to link to images: *Some elements have been removed for space. View the entire page here.here

9 Adding CSS After being transformed with the xsl file, the resulting xml file is still very elementary. More formatting can be done in the xsl, but I prefer to attach a css file to create the final polished look. View the complete css file herehere


Download ppt "XML & RDBMS By Molly Gumpert for: LIS 469: XML Fall 2014 Professor Gerry Benoit."

Similar presentations


Ads by Google