Jump to content

Parsing XML


Lyon

Recommended Posts

I have a bit of a complicated problem

 

I'm parsing XML data through PHP to create a sort of image gallery. Here is what it looks like: http://lyonbeckers.ca/index.php?page=imageuploaded.

 

The following is the XML that it is referencing

<gallery>
<image>
<imgname>Mountain</imgname>
<imgurl>assets/images/gallery/test.png</imgurl>
<imgdescription>Whaaat</imgdescription>
<imgcredit>asdfasdf</imgcredit>
<imgcopyright>asdfasdf</imgcopyright>
<imgday>17</imgday>
<imgmonth>5</imgmonth>
<imgyear>1996</imgyear>
</image>
<image>
<imgname>xfgbdfg</imgname>
<imgurl>assets/images/gallery/Screenshot-3.png</imgurl>
<imgdescription>dfgsdfg</imgdescription>
<imgcredit>sdfgsdfg</imgcredit>
<imgcopyright>sdfgsdfg</imgcopyright>
<imgday>27</imgday>
<imgmonth>5</imgmonth>
<imgyear>1993</imgyear>
</image>
<image>
<imgname>Goeman</imgname>
<imgurl>assets/images/gallery/Screenshot-Glide64.png</imgurl>
<imgdescription>wat</imgdescription>
<imgcredit>asdfa</imgcredit>
<imgcopyright>asdfasdf</imgcopyright>
<imgday>4</imgday>
<imgmonth>3</imgmonth>
<imgyear>1994</imgyear>
</image>
...

 

I've been struggling for quite a bit over how I can get it to "select" the <image> element belonging to each picture so I can remove those lines from the file when their checkbox is selected in the form and "Delete Selected Images" is submitted. I've been struggling mostly to have it recognize more than one picture if they're selected, most things i've tried only select the first image, and a few attempts have thrown me into an infinite loop.

 

Here is my form code:

 

$gallery = simplexml_load_file('assets/files/xml/imgxml.xml');

echo "<form method='post' action='' id='imageuploadform'>";
foreach ($gallery->image as $image) {
echo "<fieldset><legend><input type='checkbox' name='".$image->imgurl."' id='".$image->imgurl."' value='".$image->imgurl."' /><label for='".$image->imgname."'> ".$image->imgname."</label></legend>";
echo "<img src='".$image->imgurl."' title='".$image->imgname."' alt='".$image->imgname."' />";
echo "<dl><dt>Description:</dt><dd>".$image->imgdescription."</dd>";
echo "<dt>Credit:</dt><dd>".$image->imgcredit."</dd>";
echo "<dt>Copyright: </dt><dd>".$image->imgcopyright."</dd>";
echo "<dt>Date: </dt><dd>".$image->imgday."/".$image->imgmonth."/".$image->imgyear."</dd></dl>";
echo "</fieldset>"; 
}
echo "<fieldset><legend>Submit</legend><input type='submit' value='Delete selected images' /><input type='hidden' name='_delimg' id='delimg' value='1' /></fieldset></form>";
?>

And I just need to figure out what to put in here, I just don't even know where to begin:

if (array_key_exists('_delimg', $_POST)) {
}

 

Any suggestions, pointers, tips, etc would be greatly appreciated.

 

I'm not doing it in a mySQL database because I'm going to be using the same data in flash. Also, I've always used mySQL and wanted to try writing to file as it's something I've never really learned too much about PHP. Trying to expand the knowledge as best I can

Link to comment
https://forums.phpfreaks.com/topic/148715-parsing-xml/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.