Content Management Code

  Home arrow Content Management Code arrow Codewalkers Tutorial XML Parser
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:

     
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    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

    blog comments powered by Disqus

    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-2012 by Developer Shed. All rights reserved. DS Cluster 1 - Follow our Sitemap