Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old March 26th, 2008, 05:13 PM
Registered User
 
Join Date: Mar 2008
Location: austin, texas, USA.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help with PHP file reading XML file for output

hi there, I have a PHP page reading my XML document and creating an HTML table with a row for each entry, and a column for each attribute for that entry. There are currently two entries in the XML with 6 attributes each.

My PHP code is working correctly so far as pulling the XML in and printing it to the HTML table, but it is creating an extra blank entry for some reason, and I cannot figure out why. It adds a blank entry when it reads the XML and prints a row with no values...can anyone see my mistake?

Below is the PHP code on my PHP page:

Code:
<?php
function start_tag($parser, $name, $attrs){
    global $table_string;
    $table_string .= "<tr>
        <td width=\"100\" align=left bgcolor=#e7eee8 height=\"120px\" valign=\"middle\">
            <span class=\"listingpadding03\"><img src=\"../images/thumbs/$attrs[title].gif\" width=\"100\" height=\"100\" align=\"middle\" /></span>
        </td>
        <td width=\"90\" align=\"center\" bgcolor=#e7eee8 height=\"120px\">
            <span class=\"listingpadding03\">$attrs[artist]</span>
        </td>
        <td width=\"170\" align=\"center\" bgcolor=#e7eee8 height=\"120px\">
            $attrs[path]
        </td>
        <td width=\"120px\" align=\"center\" bgcolor=#e7eee8 height=\"120px\">
            <span class=\"listingpadding03\">$attrs[squarefootage]</span>
        </td>
        <td width=\"120px\" align=\"center\" bgcolor=#e7eee8 height=\"120px\">
            <span class=\"listingpadding03\">&nbsp;&nbsp;&nbsp;&nbsp; $attrs[bedsbaths]</span>
        </td>
        <td width=\"90px\" align=\"right\" bgcolor=#e7eee8 height=\"120px\">
            <span class=\"listingpadding03\">$attrs[price] &nbsp;&nbsp;</span>
        </td>
    </tr>
    <tr>
        <td colspan=\"6\" height=\"7\" bgcolor=\"#ffffff\"></td>
    </tr>";
}
function end_tag($parser, $name){}
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_set_element_handler($parser, "start_tag", "end_tag");
$table_string = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"#e7eee8\" width=\"816\" class=\"phptablefont\">
        <tr><td colspan=\"6\" bgcolor=\"#f6f6f6\"><img src=\"../images/list-fo.gif\" alt=\"Buffington Available Homes\" width=\"750\" height=\"22\" /></td></tr><tr><td colspan=\"6\"><img src=\"../images/list-head.gif\" alt=\"Buffington Available Homes\" width=\"816\" height=\"22\" /></td></tr>";
xml_parse($parser, file_get_contents("playlist.xml")) or die("Error parsing XML file");
$table_string .= "</table>";
echo $table_string;
?>
And below here is the very simple XML file with two entries, and six attributes for each (each entry is called "song" and each has the following values: "title", "artist", "path", "squarefootage", "bedsbaths", and "price".).

Code:
<songs><song title="mckinleya" artist="testing" path="one" squarefootage="two" bedsbaths="three" price="four" /><song title="mckinleya" artist="testing" path="one" squarefootage="two" bedsbaths="three" price="four" /></songs>
Thank you in advance if you can help me!!! -

Ryan
Reply With Quote

C. Ryan McVinney
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading xml file which is in a JAR file pradheepayyanar J2EE 2 December 26th, 2007 04:52 AM
reading a XML file connect2sandep XML 1 December 14th, 2006 03:50 AM
reading a XML file connect2sandep General .NET 0 December 13th, 2006 01:10 PM
XML Output file Neal Crystal Reports 0 October 24th, 2006 07:02 AM
Capturing\Reading File Contents into DB with PHP aingalsbe PHP How-To 2 December 30th, 2005 08:48 AM



All times are GMT -4. The time now is 07:24 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.