Jump to content

PHP edit XMLfile


M84

Recommended Posts

I'm developping an application in flash and when I create an image I want to save the info of that image in a xml file. After searching it seems that doing that would be better with php. But I'm kinda of a noob in terms of php and xml. So I was thinking of sending the images name, height and width to php and then edit a xml file that already exists. the xml file has a very simple structure:

 

<gallery>

  <image path="images/flor.JPG" width="96" height="96" />

  <image path="images/palmeiras.JPG" width="96" height="97" /> 

</gallery>

 

I already tried SimpleXML, but I dont know how to edit the actual xml file.

 

This is the php code I have now:

<?php

if (file_exists('images.xml')) {
    $sxo = simplexml_load_file('images.xml');
$new_image = $sxo->addChild("image");
$new_image->addAttribute("path","image.jpg");
$new_image->addAttribute("width","97");
$new_image->addAttribute("height","100");

    var_dump($sxo);

} else {
    exit('Failed to open test.xml.');
}
?>

 

 

It reads my xml file, and adds a new child, but how do I update that info on the actual xml file?

 

Can somebody please help me?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.