moos3
08-15-2007, 05:23 PM
I have the following code for a gallery i wrote:
$gallery_Xml = new SimpleXMLElement(utf8_encode(file_get_contents('gallery/gallery.xml')));
$author = (string)$gallery_Xml->information->author;
$copyright = (string)$gallery_Xml->information->copyright;
$desc = (string)$gallery_Xml->information->description;
$albums = $gallery_Xml->album;
$imgset;
$i = 0;
$j = 0;
echo'<h2>"Photos by '.$author.'"</h2>';
echo '<div class="info">'.$desc.'</div>';
foreach($gallery_Xml->album as $albums=>$images){
echo "boo";
switch($images){
case "title":
echo "<h2>".$images['title']."</h2></br>";
break;
case "imgfile":
echo $images['imgfile'];
break;
}
}
heres the xml document:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
# This file is part of m3xml Gallery.
#
# m3xml Gallery is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# m3xml Gallery is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# To Add a album just make a in new <album></album> node
# You must put the images in a image node
# One image per node only
# So each each album node can have many image nodes but each image node
# can only have one title node and one imgfile node.
#
# Each album node can have a name and a description(not currently used)
# Each album node must have a title
#
# Please enjoy
# Written by moos3
# Alpha date 14 AUG 2007
# Beta1 date 15 AUG 2007
-->
<gallery>
<information>
<author>Jayme Gallant</author>
<description>This is a my simple PHP gallery written by Moos3 Studios</description>
<copyright>All Rights Reserved and All Contributors Maintin own CopyRights. </copyright>
</information>
<album>
<name>Camp</name>
<desc>Pictures From Camp</desc>
<image>
<title>Up the River</title>
<imgfile>gallery/photos/camp/up_river.jpg</imgfile>
</image>
<image>
<title>River Road</title>
<imgfile>gallery/photos/camp/road_to_camp.jpg</imgfile>
</image>
<image>
<title>Up The River Road</title>
<imgfile>gallery/photos/camp/up_the_riverroad.jpg</imgfile>
</image>
<image>
<title>Down The River</title>
<imgfile>gallery/photos/camp/down_river.jpg</imgfile>
</image>
</album>
<album>
<name>Funny Pictures</name>
<image>
<title>barcode</title>
<imgfile>http://circle.ch/blog/cache/qr697.jpg</imgfile>
</image>
<image>
<title>A Tower</title>
<imgfile>http://farm2.static.flickr.com/1405/818970598_5f0934dee0.jpg?v=0</imgfile>
</image>
<image>
<title>Buddy Jesus</title>
<imgfile>gallery/photos/funstuff/buddyjesus.png</imgfile>
</image>
</album>
</gallery>
The thing is a I can't get it to work. Suggestions?
$gallery_Xml = new SimpleXMLElement(utf8_encode(file_get_contents('gallery/gallery.xml')));
$author = (string)$gallery_Xml->information->author;
$copyright = (string)$gallery_Xml->information->copyright;
$desc = (string)$gallery_Xml->information->description;
$albums = $gallery_Xml->album;
$imgset;
$i = 0;
$j = 0;
echo'<h2>"Photos by '.$author.'"</h2>';
echo '<div class="info">'.$desc.'</div>';
foreach($gallery_Xml->album as $albums=>$images){
echo "boo";
switch($images){
case "title":
echo "<h2>".$images['title']."</h2></br>";
break;
case "imgfile":
echo $images['imgfile'];
break;
}
}
heres the xml document:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
# This file is part of m3xml Gallery.
#
# m3xml Gallery is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# m3xml Gallery is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# To Add a album just make a in new <album></album> node
# You must put the images in a image node
# One image per node only
# So each each album node can have many image nodes but each image node
# can only have one title node and one imgfile node.
#
# Each album node can have a name and a description(not currently used)
# Each album node must have a title
#
# Please enjoy
# Written by moos3
# Alpha date 14 AUG 2007
# Beta1 date 15 AUG 2007
-->
<gallery>
<information>
<author>Jayme Gallant</author>
<description>This is a my simple PHP gallery written by Moos3 Studios</description>
<copyright>All Rights Reserved and All Contributors Maintin own CopyRights. </copyright>
</information>
<album>
<name>Camp</name>
<desc>Pictures From Camp</desc>
<image>
<title>Up the River</title>
<imgfile>gallery/photos/camp/up_river.jpg</imgfile>
</image>
<image>
<title>River Road</title>
<imgfile>gallery/photos/camp/road_to_camp.jpg</imgfile>
</image>
<image>
<title>Up The River Road</title>
<imgfile>gallery/photos/camp/up_the_riverroad.jpg</imgfile>
</image>
<image>
<title>Down The River</title>
<imgfile>gallery/photos/camp/down_river.jpg</imgfile>
</image>
</album>
<album>
<name>Funny Pictures</name>
<image>
<title>barcode</title>
<imgfile>http://circle.ch/blog/cache/qr697.jpg</imgfile>
</image>
<image>
<title>A Tower</title>
<imgfile>http://farm2.static.flickr.com/1405/818970598_5f0934dee0.jpg?v=0</imgfile>
</image>
<image>
<title>Buddy Jesus</title>
<imgfile>gallery/photos/funstuff/buddyjesus.png</imgfile>
</image>
</album>
</gallery>
The thing is a I can't get it to work. Suggestions?