0

I'm trying to build one of my first php procedure but I'm struggling on an apparently stupid issue and I need your help:

I need to load and modify an xml file and then I have to send via curl

here it is what I've done so far:

$userID='John';
$Action="Read";
$Quarter="2";
$xml=simplexml_load_file("test/xml/testxml.xml") or die("Error: Cannot create object");
$xml->User->UserID=$userID;
$xml->Action=$Action;
$xml->Quarter=$Quarter;

$responseXml = sendHttpRequest($xml);

the problem, I suppose, is that sendHttpRequest requires $xml to be a string, while in my example it is an object I'm quite sure about this since if I build the xml as a string..

$xml = '<?xml version="1.0" encoding="utf-8" ?>';
$xml .= '<Request>';
$xml .= "<User><UserID>$userID</userID></User>";
$xml .= "<Action>$Action</Action>";
$xml .= "<Quarter>$Quarter</Quarter>";    
$xml .= '</Request>';

sendHttpRequest function works.

Therefore, hwo to transform $xml into a string?

I've seen some example using

(string) $xml-> ....

but these examples extract a node of the xml as string, while I need it fully.

Thanks Joe

1 Answer 1

1

got it..

simpler as expected:

$xml=$xml->asXML();

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.