I have an XML file test.xml
<?xml version="1.0"?> <info> <user> <name> <firstname>FirstName</firstname> <lastname>Last Name</lastname> <nameCoordinate> <xName>125</xName> <yName>20</yName> </nameCoordinate> </name> </user> </info>
I am trying to update node xName and yName using PHP when submitting a form. So, I uploaded the file using simplexml_load_file (). PHP form action code below
<?php $xPostName = $_POST['xName']; $yPostName = $_POST['yName']; //load xml file to edit $xml = simplexml_load_file('test.xml'); $xml->info->user->name->nameCoordinate->xName = $xPostName; $xml->info->user->name->nameCoordinate->yName = $yPostName; echo "done"; ?>
I want to update node values, but the code above seems to be wrong. Can someone help me fix this?
UPDATE: My question is somewhat similar to this Updating an XML file using PHP , but here I am loading the XML from an external file, and also updating the element, not the attribute. Where my confusion lies.
xml php simplexml
ptamzz Jan 20 '11 at 2:00 p.m. 2011-01-20 14:00
source share