0

I can retrieve certain information with a rest command, the data it shows (in the browser) is already an XML. How do I save it to an XML file on the server after retrieving the information.

I have already tried it with the $dom-save command but I seem to do something wrong. Any help would be appreciated. See below for code (I want to save the $response to XML.)

<?php

require_once 'includes/rest_connector.php';
require_once 'includes/session.php';

// check to see if we start a new session or maintain the current one
checksession();

$rest = new RESTConnector();

$url = "/api/tax_codes/0/";
$rest->createRequest($url,"GET", null, $_SESSION['cookies'][0]);
$rest->sendRequest();

$response = $rest->getResponse();
$error = $rest->getException();

// save our session cookies
if ($_SESSION['cookies']==null) 
$_SESSION['cookies'] = $rest->getCookies();

// display any error message
if ($error!=null)
echo $error;

// display the response
if ($response!=null)
echo $response;
else
echo "There was no response.";  


?>

2 Answers 2

1

The RESTConneconnector is a specific class Lightspeed. I solved it by using this:

ibxml_use_internal_errors(true);//load if improperly formatted
file_put_contents("exportProduct.xml", $responseProduct);

So it was very easy in the end :)

0

I dont know any about RESTConnector class. But I suppose, you can try something like it:

$dom = new DOMDocument('1.0','utf-8');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->loadXML($response->asXML());
$dom->save($this->fileexport);

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.