I've 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'm trying to update the node xName & yName using PHP on a form submission. So, I've loaded the file using simplexml_load_file(). The PHP form action code is 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 the node values but the above code seems to be incorrect. Can anyone help me rectify it??
UPDATE: My question is somewhat similar to this Updating a XML file using PHP but here, I'm loading the XML from an external file and also I'm updating an element, not an attribute. That's where my confusion lies.