Greetings,
I have an issue i hope you can help me with regarding parsing an xml file to table in php.
I have an input form that writes an xml file. (it works)
the xml file it writes is in this format:
<?xml version="1.0" encoding="iso-8859-1"?>
<images>
<title>2</title>
<description>2</description>
<tmg></tmg>
<img>2</img>
</images>
Now, this is what I need for my flash gallery to play and I can't change that.
The Problem is when I list all the images in the admin section to add and delete, I am getting a parsing error.
Clue the parser will work if I format the xml file like this:
<images>
<image title="2" description="2" tmb="2" img="2" />
</images>
- Finally, yes I would write to that format using:
<?php
$write_string = "<images>";
foreach($images_final as $image){
$write_string .= "<image title=\"$image[title]\" description=\"$image[description]\" tmb=\"$image[tmb]\" img=\"$image[img]\" />";
}
$write_string .= "</images>";
$fp = fopen("gallery.xml", "w+");
fwrite($fp, $write_string) or die("Error writing to file");
fclose($fp);
?>
....but my flash gallery won't work.
Here is what I'm using that is generating the error.
<?php
function start_tag($parser, $name, $attrs){
global $table_string;
$table_string .= "<tr><td>[title]</td><td>[description]</td><td>[tmb]</td><td>[img]</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>
<tr><th>Title</th><th>Description</th><th>Thumbnail</th><th>Image</th></tr>";
xml_parse($parser, file_get_contents("gallery.xml")) or die("Error parsing XML file");
$table_string .= "</table>";
echo $table_string;
?>
Thank you in advance for your help!!
Alan
Reply With Quote