tags:

views:

312

answers:

2

Hi ,

How can I edit the value's in a xml file using simpleXML ?

I know how to create just not how to edit the value in a exciting file ?

A: 

Load your XML with SimpleXML and make the changes. Then you can use the asXML method to save the XML to a file (you pass the filename as the argument):

$xml = new SimpleXMLElement( $xmlString );
// do the manipulation here
$xml->asXML ( '/path/to/your/file.xml' );
Jan Hančič
+2  A: 

Sure you can edit with SimpleXML:

$input = <<<END
<?xml version='1.0' standalone='yes'?>
<documents>
  <document>
    <name>spec.doc</name>
  </document>
</documents>
END;

$xml = new SimpleXMLElement($input);
$xml->document[0]->name = 'spec.pdf';
$output = $xml->asXML();

Take a look at the examples.

cletus