PHP et XML: changer la valeur dans un node
Bonjour,
Je teste des modification dans un fichier xml avec php et je n'y arrive pas. Voici mon fichier xml.
Code:
1 2 3 4 5 6 7 8
|
<?xml version="1.0" encoding="UTF-8"?>
<root>
<light>off</light>
<spray>off</spray>
<sensor>on</sensor>
<nutrient>off</nutrient>
</root> |
Je veux changer la valeur "off" de light par "on". Voici mon code en php qui ne fonctionne pas:
Code:
1 2 3 4 5
|
<?php
$doc = new DOMDocument();
$doc->load( 'maincontrol.xml' ) or die("No xml file");
$doc->getElementsByTagName('light')->item(0)->nodeValue = "on"; |
Qu'est ce qui ne va pas ?