Change element in XML file

Discussion in 'PHP' started by Packy, Dec 7, 2007.

  1. #1
    Simple problem, hope simple solution.

    How to edit element in XML file?

    Here what I have been trying...

    <?php
    $dom = new DOMDocument;
    $dom->load('XML/sample.xml');

    if ($dom->getElementsByTagname('Static_IP')) {
    $Static_IP = $dom->getElementsByTagname('Static_IP');
    $Static_IP_value = $Static_IP->item(0)->firstChild->nodeValue;

    print "IP address: $Static_IP_value";

    $IPaddress =10.10.1.1;

    ????????????
    How to add this variable into te element name Static_IP
    ????????????



    $dom->formatOutput = true;
    $sample = $dom->saveXML();
    $dom->save('XML/sample.xml');

    ?>
     
    Packy, Dec 7, 2007 IP
  2. Packy

    Packy Guest

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    As I said, simple solution that I could not find at the moment :)

    $Static_IP_value = '10.10.10.111';
    $dom->getElementsByTagname('Static_IP')->item(0)->firstChild->nodeValue = $Static_IP_value;
     
    Packy, Dec 11, 2007 IP