XML Node Update

Discussion in 'XML & RSS' started by shiva_rnm, Jul 26, 2008.

  1. #1
    Hi All,

    I have a written a method in SimpleXML parser to update node value for xml file. my method does updates node value but it deletes all the child nodes for it. I want to avoid the deleting of child nodes.

    If u have method for updating node plz send it to me.
    my xml file,

    <?xml version="1.0" encoding="UTF-8"?>
    <root> <q1.php language="fr|pt|en|in" editable="Yes">Description<array1 language="fr|pt|en|in" editable="Yes" type="Array" index="Yes">Comment</array1></q1.php></root>


    this is my method ,
    <?php
    $xml = simplexml_load_file('shiva.xml');
    $result = $xml->xpath('/root');
    $file = 'q1.php';
    $result[0]->$file = 'modified';
    $fp = @fopen('shiva.xml', "w+");
    @fwrite($fp, $xml->asXML());
    @fclose($fp);

    ?>


    this is output i'm getting

    <?xml version="1.0" encoding="UTF-8"?>
    <root> <q1.php language="fr|pt|en|in" editable="Yes">modified</q1.php></root>


    plz reply me ASAP
     
    shiva_rnm, Jul 26, 2008 IP