I've this xml file.
<resources>
  <resource>
    <code>THB</code>
    <rate>35.570000</rate>
    <ts>1480703728</ts>
  </resource>
  <resource>
    <code>HKD</code>
    <rate>65.570000</rate>
    <ts>1480447028</ts>
  </resource>
</resources>
How do I find the specific code name and update/replace/edit the rate using PHP?
For an example, I would like to update HKD's rate and timestamp.
I've tried using this method but it didn't work out.
foreach ($Ratexml->resource as $resource) //loop thru every resource
{
    $RateCode = $resource->code; //get the code
    if($RateCode == "HKD") //find the match
    {
        $resource->resource->rate= "123"; //replace the value with desired value but failed 
    }
}
This happened instead when I try to replace the value of the HDK..
 <resources>
    <resource> //Start HKD
         <code>HKD</code>
         <rate>7.755150</rate>
         <ts>1480703739</ts>
     <resource><rate>123</rate></resource>
   </resource> //end HKD
</resources>
The output that I actually wanted is something like this. The HKD's rate is replaced to 123.
<resources>
  <resource>
    <code>THB</code>
    <rate>35.570000</rate>
    <ts>1480703728</ts>
  </resource>
  <resource>
    <code>HKD</code>
    <rate>123</rate>
    <ts>1480447028</ts>
  </resource>
</resources>
Thanks to whoever that help me out as I've been stuck here for so long. Cheers.
 
    