First of all I want to thank You guys from KIRUPA for the great knowledge You share over the years. Now I need help from You. I googled this article on KIRUPA.COM http://www.kirupa.com/web/xml_php_parse_beginner.htm about XML parsing.
I touched the php code lightly and I cant manage to display the results in a tables. Can someone rewrite the code that will draw table with x rows and 2 columns and it will drag info from certain xml file.
Thanks again, and keep up the GREAT work.
Sincerely,
Gorast
the php code I have right now from xml_beginner.php that output plain text is:
<?php
// The XML file that you wish to be parsed
$file = "xml_beginner.xml";
// This function tells the parser what to do with the data once it reaches the contents
// that appear between tags.
function contents($parser, $data){
echo $data;
}
// This function tells the parser to place a <b> where it finds a start tag.
function startTag($parser, $data){
echo "<b>";
}
// And this function tells the parser to replace the end tags with "<b><br />"
function endTag($parser, $data){
echo "</b><br />";
}
// These lines create the parser and then set the functions for the parser to use when
// reading the document.
$xml_parser = xml_parser_create();
// Sets the functions for start and end tags
xml_set_element_handler($xml_parser, "startTag", "endTag");
// Sets the function for the contents/data
xml_set_character_data_handler($xml_parser, "contents");
// Opens the file for reading
$fp = fopen($file, "r");
// Read the file and save its contents as the variable "data"
$data = fread($fp, 80000);
// This if statement does two things. 1) it parses the document according to our
// functions created above. 2) If the parse fails for some reason it returns an
// error message and also tells us which line the error occured at.
if(!(xml_parse($xml_parser, $data, feof($fp)))){
die("Error on line " . xml_get_current_line_number($xml_parser));
}
// Free the memory used to create the parser
xml_parser_free($xml_parser);
// Close the file when you're done reading it
fclose($fp);
?>