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  
Forums Sitemap 
Dedicated Servers  
Download TestComplete 
JMSL Numerical Library 
IBM® developerWorks
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! Driving Business Success with Rational Process Library

    Join this webcast, to learn how the Rational Process Library can help with compliance issues, drive process improvement, and assist in service-oriented architecture (SOA) or Agile development. We will take a peek into the Rational Process Library with content around software and systems engineering (including RUP), operations and systems management, program and portfolio management, and asset and SOA governance.
    FREE! Go There Now!


    NEW! BlammoSplat: Build a community Web site of OpenLaszlo animations, Part 3: The community animation

    Learn to enable users to both rate existing animations and to combine existing animations into new snippets. This is the third in a series of three tutorials that chronicle the building of a site that enables collaborative discussion and animation building using Domino and OpenLaszlo.
    FREE! Go There Now!


    NEW! Download IBM Rational Developer for System z

    Download a free trial version of IBM Rational Developer for System z, software that can help you deliver core development capabilities; the power of Java Platform, Enterprise Edition (Java EE); and rapid application development support to diverse enterprise application development teams. With comprehensive development tools to help create, deploy and maintain traditional enterprise and composite applications, Rational Developer for System z enables developers with different technical backgrounds to easily participate in important technology projects.
    FREE! Go There Now!


    NEW! Download the free Web Application Security eKit

    Discover how IBM Rational AppScan Standard Edition can help you detext vulnerabilities in your web applications in the Web Application Security eKit. IBM Rational AppScan is a leading suite of automated web application security solutions that scan and test for common Web application vulnerabilities. The new Web Application Security eKit provides you with valuable resources, including white papers, demos, and additional information on the benefits of testing your Web applications.
    FREE! Go There Now!


    NEW! Hello World: Monitor a simple business process using WebSphere Business Monitor V6.0.2

    This tutorial shows new users of IBM WebSphere Business Monitor Version 6.0.2 how to perform the "Hello World" equivalent for monitoring business process applications. It is intended to help you get familiar with the capabilities of the product.
    FREE! Go There Now!


    NEW! Hello World: WebSphere Service Registry and Repository

    Manage, govern, and share services across your organization by using WebSphere Service Registry and Repository. Follow the hands-on exercises to learn how to navigate the Web interface to publish, find, reuse, and update services.
    FREE! Go There Now!


    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! Trial download: IBM Rational Method Composer V7.2

    Get a free trial download of the latest version of IBM Rational Method Composer V7.2 which helps you deliver customized yet consistent process guidance to your project teams and IT organization, and includes the latest version of IBM Rational Unified Process (RUP), which has provided process guidance to teams since 1996.
    FREE! Go There Now!


    NEW! Webcast: IBM Rational Build Forge - Beyond the Build

    The discipline of assembling and delivering software is maturing beyond standard developer-centric compile/test software builds. The end-to-end software development lifecycle is emerging as the new focus moves “Beyond the Build.” Join this on demand webcast to learn about methods for streamlining software delivery and key capabilities of the IBM Rational Build Forge framework for automating build and release management in environments of any size.
    FREE! Go There Now!


    NEW! Whitepaper: Delivering SOA solutions: service lifecycle management

    The unprecedented scope of a service-oriented architecture (SOA) initiative brings to the forefront a number of management and governance issues that were sidestepped in the past. The key to a successful SOA implementation is managing and governing activities throughout the entire SOA delivery lifecycle by ensuring that services conform to the needs of all of the business’s stakeholders. Learn how service lifecycle management allows the business to ensure that the process by which services are defined, created, tested, deployed, optimized and retired is manageable, repeatable and auditable.
    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-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway