SimpleXML question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
callison
Forum Newbie
Posts: 1
Joined: Wed Aug 06, 2008 4:40 pm

SimpleXML question

Post by callison »

Code: Select all

 
Reference XML file
<?xml version="1.0" encoding="utf-8"?>
<data>
    <software software_number="1" department="it" dev="adobe" prod="photoshop" sn="00000" pass="" machine="it3" date="08-06-2008"/>
    <software software_number="4" department="it" dev="microsoft" prod="windows xp" sn="1234" pass="" machine="it3" date="08-06-2008">this is a test!</software>
</data>
Hi, I have this (above) xml file that I am having trouble editing via form submission.

Code: Select all

function updateSoftware()
{
    $xmlstr = file_get_contents('software.xml');
    $xml = new XMLElement($xmlstr);
    
    $id = strtolower($_POST['id']);
    
    $dev = strtolower($_POST['dev']); 
    $prod = strtolower($_POST['prod']); 
    $sn = strtolower($_POST['sn']);
    $pass = strtolower($_POST['pass']);
    $machine = strtolower($_POST['machine']);
    $dept = strtolower($_POST['dept']);
    $comments = strtolower($_POST['comments']);
    
    $update = $xml->xpath("//software[starts-with(@software_number, '".$id."')]");
 
    [b]$update[0] = $comments;[/b]
 
    $update[0]['dev'] = $dev;
    $update[0]['prod'] = $prod;
    $update[0]['department'] = $dept;
    $update[0]['sn'] = $sn;
    $update[0]['pass'] = $pass;
    $update[0]['machine'] = $machine;
    
    $xmlfile = fopen('software.xml', 'w');
    fwrite($xmlfile, $xml->asPrettyXML());
    fclose($xmlfile);
    echo "<br /><br /><a href='index.php'>OK! That took long enough(right?) Click here, go home</a>";
    
}
Line 18 (boldface) I am trying to update the tag itself... but I don't know the correct way of referencing it. Tried to look up on php.net but no luck.. anyone help?
Post Reply