Use PHP to post an xml file to API and echo returned xml

D4RK_HACK3R

New Member
Bear with me I'm more of a designer than a developer trying to get access to an XML feed so I can start manipulating it into tables.The idea is that using CURL the string \[code\]$xmlString\[/code\] is posted to the API and then the api will return the requested fields the only instructions I have at the moment are the ones commented below.Can anyone help or even offer a more elegant solution I may be approaching this all the wrong way\[code\]// all requests must be UTF-8 encoded// root node is <request>// must contain a <header> which must contain a valid <userId> and <password>// must contain a <body> which must contain a valid <command>// <body> can also contain a <parms> element which in turn contains one or more <parm> elements// sequence is important so the parameter must exist even if optional// each API determines the number of <parm> elements that must be defined, if any// all responses are UTF-8 encoded// root node is <response>// will contain a <header> which in turn will contain a <success> element with value 1 for yes or 0 for no// if <success> is no ("0") then the next element in <header> will be <error> containing an error message// if <success> is yes ("1") then <response> will contain a <body> which will contain one or more <record> elements// the format of the <record> elements is determined by the API// uncomment the alert(xmlStr) statement below to see the XML response$xmlString = '<?xml version="1.0" encoding="UTF-8"?>' .'<request>' .'<header>' . '<userId>hidden</userId>' . '<password>hidden</password>' .'</header>' .'<body>' . '<command>searchJobs</command>' . '<parms>' . // maxHits: for top five jobs put 5 here (integer)(optional) '<parm>100</parm>' . // space delimited list of vacancy statuses (required) '<parm>Open</parm>' . // space delimited list of vacancy categories (optional) '<parm></parm>' . // space delimited list of vacancy categories 2 (optional) '<parm></parm>' . // space delimited list of vacancy categories 3 (optional) '<parm></parm>' . // preferred location (optional) '<parm></parm>' . // preferred salary (integer)(optional) '<parm></parm>' . // list of keywords and/or double-quoted phrases (optional) '<parm></parm>' . '</parms>' .'</body>' .'</request>';$url = "http://www.example.com/crpc/api";$ch = curl_init(); // initialize curl handlecurl_setopt($ch, CURLOPT_URL,$url); // set url to post tocurl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variablecurl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');curl_setopt($ch, CURLOPT_TIMEOUT, 4); // times out after 4scurl_setopt($ch, CURLOPT_POSTFIELDS, $xmlString); // add POST fields$result = curl_exec($ch); // run the whole processvar_dump($result); //contains response from server\[/code\]
 
Back
Top