Content Management Code
  Home arrow Content Management Code arrow Codewalkers Tutorial XML Parser
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
CONTENT MANAGEMENT CODE

Codewalkers Tutorial XML Parser
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 2
    2002-02-06

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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

     

    IBM® developerWorks developerWorks - FREE Tools!


    NEW! Integrating XML into Your Enterprise Using Data Federation

    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!


    NEW! Run your first CICS application on a PC using TXSeries for Windows

    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!


    NEW! Download a free trial of Lotus Quickr 8.0

    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!


    NEW! Project and Portfolio Management Executive Resource Kit

    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!


    NEW! "ebook: Exploring IBM SOA Technology & Practice

    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!


    NEW! Using Rational Business Developer to enhance your developer productivity

    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!


    Role of Integrated Requirements Management in Software Delivery

    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!


    NEW! Rational 'Talks to You' Teleconference Series

    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!


    NEW! Discovering the value of WebSphere Process Server

    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!


    NEW! Trial download: IBM Rational Functional Tester V7.0.1

    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!

    CONTENT MANAGEMENT CODE ARTICLES

    - V2 CMS - Content Management System
    - VSNS Lemon
    - Country List For Forms Using SQL
    - eggblog
    - Table generation class
    - STP Simple Template Parser
    - class Vision_To_Form_Elements
    - Cascade Drop Down
    - Cura - CMS
    - Syntax Desktop
    - 216 color table
    - Simple Mini Poll class library (SimPoll)
    - Regex Generator
    - Siteseed
    - Company WebSite Builder PRO





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek