Results 1 to 3 of 3

Thread: Using XML

  1. #1
    Join Date
    Jan 2008
    Posts
    42
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Using XML

    I have searched and searched and have read tutorials but I still don't get it. I have been trying to get a php script of mine to work with XML but I can't get it to work. I got it to parse the file correctly and give me a print out, but I can't figure out how to delete parts and append new parts. Here is the code I am using to parse it and display:

    Code:
    $xmlFileData = file_get_contents("gallery.xml");
    $xmlData = new SimpleXMLElement($xmlFileData);
    foreach($xmlData->image as $image) {
    ?>
    <tr>
    <td>Delete</td>
    <td><? echo $image->filename ?></td>
    <td><? echo $image->caption ?></td>
    </tr>
    This works just fine. What I need though is code for that delete button to delete a record at a time, and I need code so at the bottom of this page I can put a form for appending to this file. This code I cannot find no matter how long I search, it is getting nerve racking.

    Thanks for any help you can give me.

  2. #2
    Join Date
    Jan 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Well, you need to add a key for each record:
    PHP Code:
    $xmlFileData = file_get_contents("gallery.xml");
    $xmlData = new SimpleXMLElement($xmlFileData);
    foreach($xmlData->image as $key=>$image) {
    ?>
    <tr>
    <td><a href="?delete=$key">Delete</a></td>
    <td><? echo $image->filename ?></td>
    <td><? echo $image->caption ?></td>
    </tr>
    after that you need to remove that record from the list:
    PHP Code:
    foreach($xmlData->image as $key=>$image) {
        if (
    intval($_GET['delete']) == $key) {
           
    // delete the line
        
    }
    }
    ...... 

  3. #3
    Join Date
    Jan 2008
    Posts
    42
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default

    Thanks, question though. What is the delete command to actually delete the part of the xml file? And what is the command to append a new area to the xml file. This is what my xml file looks like:

    Code:
    <simpleviewerGallery maxImageWidth="480"  maxImageHeight="360" textColor="0xFFFFFF" frameColor="0xffffff" frameWidth="10" stagePadding="20" thumbnailColumns="3" thumbnailRows="3" navPosition="left" title="miaDios Galeria" enableRightClickOpen="false" backgroundImagePath="" thumbPath="" imagePath="" >
    <image>
    	<filename>1.jpg</filename>
    	<caption>Caption 1</caption>	
    </image>
    <image>
    	<filename>1.jpg</filename>
    	<caption>Caption 2</caption>	
    </image>
    </simpleviewerGallery>
    What I want to delete is a whole image area and add new image areas.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •