I'm having some difficulties in changing XML Node values with PHP.
My XML is the following
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ProcessTransaction
xmlns="http://example.com">
<TransactionRequest
xmlns="http://example.com">
<Header>
<RequestType>SALE</RequestType>
<RequestMethod>SYNCHRONOUS</RequestMethod>
<MerchantInfo>
<PosName>kwstasna</PosName>
<PosID>1234</PosID>
</MerchantInfo>
</Header>
</TransactionRequest>
</ProcessTransaction>
</soap:Body>
</soap:Envelope>
And i want to change PosName and PosID.
The XML is received from a POST Request.
If i print_r($REQUEST['xml']
I get the values in text.
And what i've tried is the following
$posid = '321';
$posname = 'nakwsta';
$result = $xml->xpath("/soap:Envelope/soap:Body/ProcessTransaction/TransactionRequest/Header/MerchantInfo");
$result[0]->PosID = $posid;
$result[0]->PosName = $posname;
echo $result;
But i get an empty array Array[]
I think my mistake is in the values of <soap:Envelope for example.
Anyone that had the same issue and find out the way to solve it?
Thanks a lot for your time.
xmlns="http://example.com", because this is the node that you are trying to use (see first example in the manual)