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
https://forums.phpfreaks.com/topic/40773-php-edit-xmlfile/
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.