This is the parser that I use for the Tutorials here on Codewalkers. I store the XML file and some related information in the database, but you could easily modify this to take it from a file. This isn't exactly how my page looks, but its pretty close...
By : Matt
<?
$query = "SELECT title,date,author,xml,views FROM cw_tutorials WHERE id=" . $show;
$result = $db->db_query($query);
$num_rows = $db->db_numrows($result);
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
$row = $db->db_fetch_array($result);
xml_parse_into_struct($parser,$row['xml'],$vals,$index);
xml_parser_free($parser);
$display = 0;
$countpages = 0;
echo "<TABLE width=\"95%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
echo "<TR>\n";
echo "<TD>\n";
for($i = 0; $i < count($vals); $i++) {
if($vals[$i]['tag'] == 'title' && $display == 0) {
echo "<CENTER><h2>" . $vals[$i]['value'] . "</h2></CENTER>\n";
}
if($vals[$i]['tag'] == 'author' && $display == 0) {
echo "<CENTER>by " . $vals[$i]['value'] . "</CENTER><BR><HR width=\"95%\">\n";
}
if($vals[$i]['tag'] == 'page' && $vals[$i]['type'] == 'open') {
$display = 1;
$countpages++;
}
if($vals[$i]['tag'] == 'page' && $vals[$i]['type'] == 'close') {
$display = 0;
}
if(($vals[$i]['tag'] == 'title') && ($display == 1)) {
$titles[$countpages] = $vals[$i]['value'];
}
if(($display == 1) && ($countpages == $page)) {
if($vals[$i]['tag'] == 'paragraph') {
$vals[$i]['value'] = ereg_replace("%url%", "<a href=\"", $vals[$i]['value']);
$vals[$i]['value'] = ereg_replace("%/url%", "</a>", $vals[$i]['value']);
$vals[$i]['value'] = ereg_replace("%text%", "\" target=\"blank\">", $vals[$i]['value']);
echo "<p>" . $vals[$i]['value'] . "</p>\n";
}
if($vals[$i]['tag'] == 'title') {
echo "<h3><b>" . $vals[$i]['value'] . "</b></h3>\n";
}
if($vals[$i]['tag'] == 'code') {
echo "<TABLE width=\"90%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
echo "<TR>\n";
echo "<TD>";
if(ereg("%php%",$vals[$i]['value'])) {
highlight_string("<?PHP\n" . trim(ereg_replace("%php%","",$vals[$i]['value'])) . "\n?>");
} else {
highlight_string(trim($vals[$i]['value']));
}
echo "</TD>\n";
echo "</TR>\n";
echo "</TABLE>\n";
echo "<BR>\n";
}
if($vals[$i]['tag'] == 'image') {
echo "<p><IMG SRC=\"" . $vals[$i]['value'] . "\" border=\"0\"></p>\n";
}
}
}
if($page > 1 || ($countpages - $page) > 0) {
echo "<HR width=\"95%\">\n";
}
echo "</TD>\n";
echo "</TR>\n";
echo "</TABLE>\n";
echo "<CENTER>\n";
if($page > 1 || ($countpages - $page) > 0) {
echo "<FORM ACTION=\"http://codewalkers.com/tutorials.php?show=" . $show . "\" METHOD=\"POST\" name=\"navform\">";
if($page > 1) {
echo "<input type=\"hidden\" name=\"prevvalue\" value=\"" . ($page - 1) . "\">";
echo "<input type=\"submit\" name=\"previous\" value=\"Previous\">";
}
if(($countpages - $page) > 0) {
echo "<input type=\"hidden\" name=\"nextvalue\" value=\"" . ($page + 1) . "\">";
echo "<input type=\"submit\" name=\"next\" value=\"Next\">";
}
echo "</FORM>";
}
echo "<FORM ACTION=\"tutorials.php\" METHOD=\"POST\" name=\"sectionform\">\n";
echo "Jump to Section: ";
echo "<SELECT name=\"section\">\n";
for($z=1;$z <= count($titles);$z++) {
if($page == $z) {
echo "<OPTION value=$z SELECTED>$titles[$z]</OPTION>\n";
} else {
echo "<OPTION value=$z>$titles[$z]</OPTION>\n";
}
}
echo "</SELECT>\n";
echo "<input type=\"hidden\" name=\"tutorial\" value=\"$show\">\n";
echo "<input type=\"submit\" name=\"submit\" value=\"submit\">\n";
echo "</FORM>\n";
echo "</CENTER>\n";
?>
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More Content Management Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
XML has become a common way of storing business data as flat files and many data server vendors including IBM have provided ways to store this data within relational database systems. Increasingly collections of XML files are accessed like databases using an xQuery and other XML standard mechanisms. Businesses find the need to combine the traditional tabular structured data with XML formatted data. In this webcast, you’ll learn about IBM’s WebSphere Federation Server technology, which provides users with the ability to integrate these two data formats. FREE! Go There Now!
|
|
|
|
Learn the basics of the IBM Customer Information Control System (CICS). With a hands-on exercise, learn how to get your first CICS application up and running on your desktop using TXSeries V6.1 for Windows. The tutorial shows you how to download and install a free trial version of TXSeries V6.1. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial version of Lotus Quickr 8.0, which enables collaboration by transforming the way everyday business content such as documents, rich media, photos, and video can be shared. Lotus Quickr makes it faster and easier to share content of all types (not just documents) within virtual teams. It is designed to make it easier to collaborate across organizational boundaries, while continuing to work within the context of familiar desktop applications. FREE! Go There Now!
|
|
|
|
Portfolio Management is about effectively managing portfolio value by aligning portfolio investments with business goals. This complimentary e-kit provides a collection of materials that can help you understand how IBM Rational enables and automates best practices for improved governance and clear visibility into portfolio and project performance across the entire IT project lifecycle. FREE! Go There Now!
|
|
|
|
Learn field-tested SOA principles, methodology, technology and implementation from the global SOA market leader - in a new e-book by an IBM SOA expert. Written by IBM Certified SOA Solution Designer Bobby Woolf, "Exploring IBM SOA Technology & Practice" is the ultimate insider's guide to SOA - a PDF e-book packed cover to cover with IBM's specific advice on how to make your SOA implementation a success. FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference, to hear how Enterprise Generation Language (EGL) eliminates the need for tedious and error-prone low level coding, so developers can focus on business requirements. EGL extends the Rational software development platform with a simplified programming language that enables developers who have little or no experience with Java, Web technologies or Service Oriented Architecture, to create enterprise-class applications and services quickly and easily. It also allows developers who may have little or no mainframe programming experience to quickly create traditional mainframe components. FREE! Go There Now!
|
|
|
|
As organizations integrate software into every aspect of business, they are constantly pressured to deliver faster, better, and cheaper results. Unfortunately, a “dis-integrated” software delivery approach reduces returns while increasing costs. This IBM Rational White Paper shows how Integrated Requirements Management aligns organizations around maximizing value and keeping pace with change. FREE! Go There Now!
|
|
|
|
This Fall, IBM Rational talks to you directly through a special teleconference series giving you access to the best minds in IBM Rational - product experts and market thought leaders who will answer your questions during these pre-scheduled telephone conference calls. Register today! FREE! Go There Now!
|
|
|
|
WebSphere Process Server delivers a unique integration framework that simplifies existing IT resources. Often, as IT assets grow to support business demand, so too does their complexity and manageability. In this webcast, we’ll discuss how WebSphere Process Server helps deliver an SOA infrastructure that provides a common model to orchestrate, mediate, connect, map, and execute the underlying IT functions. Discover how WebSphere Process Server simplifies integration of business processes by leveraging existing IT assets as reusable services without the complexities of traditional integration methodologies. FREE! Go There Now!
|
|
|
|
Get a free trial download of the latest version of IBM Rational Functional Tester V7.0.1. Rational Functional Tester is an automated functional and regression testing solution for QA teams concerned with the quality of their Java, Microsoft Visual Studio .NET, and Web-based applications. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |