Using PHP to dynamically create XML file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
memerson
Forum Newbie
Posts: 2
Joined: Wed Apr 18, 2007 6:12 am

Using PHP to dynamically create XML file

Post by memerson »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi

I am working on a file that uploads an XML file to a server, but the XML file needs to be dynamically generated from the results of an XML request to an API. So, rather than directly setting the source as a specific file I need to use the results from a request to make the XML file, then ftp it to the server.

My code is as follows:

Code: Select all

$source = "source.xml";
$destination = "destination/newfilename.xml";

require_once("xml_feed_creator.php");
$xmlFeed = new xmlFeedCreator();
$xmlFeed->CreateXmlFeed($source, $destination);
but the "source.xml" needs to be the dynamically created file which is produced using the following request:

Code: Select all

function makeRequest($api,$user,$check,$type,$params){
$str ="XML_REQUEST=";
$str.="<request>";
$str.="<authorise><email>".$user."</email><checkcode>".$check."</checkcode></authorise>";
$str.="<type>".$type."</type>";
$str.="<parameters>".$params."</parameters>";
$str.="</request>";
return cURL($api,$str);
}
Then, I have my cURL function.

Code: Select all

function cURL($link,$poststring){
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $link);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $poststring);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($ch, CURLOPT_TIMEOUT, 15);
$response = trim(curl_exec ($ch));

return $response;
}
So, I just need to get the results from the XML request, and stick it in a new XML file which needs to be assigned to the $source variable, in order to upload it.

Hope this makes sense, I'm not great at explaining things :D


Michael.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Re: Using PHP to dynamically create XML file

Post by volka »

memerson wrote:So, I just need to get the results from the XML request, and stick it in a new XML file which needs to be assigned to the $source variable, in order to upload it.
Actually I think you'd be happier with a method that takes the xml string instead of the filename. xmlFeedCreator, where does this class come from?
memerson
Forum Newbie
Posts: 2
Joined: Wed Apr 18, 2007 6:12 am

Post by memerson »

Actually, I have the solution. Thanks. :)
Post Reply