Send a client xml file to server

Hi, I need import to db information from XML.
I use control aplication to do it, with field document (file name) to get the client file into variable.
Into onValidate event, I put:
$xml = simplexml_load_file({archivoImportar});
print_r($xml);

But popup this error:
simplexml_load_string(): Entity: line 1: parser error : Start tag expected, ‘<’ not found
simplexml_load_string(): EXP20150108-7796597.SQL
simplexml_load_string(): ^

If I use a control Document (Database), popup this error at compilation time:
The table or the multi-upload fields were not informed.

Any helps about how I can send and process a client xml file?
Thanks!

I hope it will be helpful, but the next sample loads a series of payment gateways (banks) in xml format. Point here is that the smplexml_loads_string is containing the xml. I suspect that your file is not read due to some reason.


$xmlstring = file_get_contents('https://www.xxxxxxxxxx.xxx/ideal/getissuers.php?format=xml');
$xmlObject = simplexml_load_string($xmlstring);

// now process each bank into the database

foreach ($xmlObject->children() as $node) {
        $arr = $node->attributes();  	// returns an array
        $id=$arr["id"];     			// get the value of this attribute
        $bank=$node;        			// get bank description

// Insert record
$insert_sql = "INSERT INTO ndbank (bankid, bankdesc) values ('".$id."', '".$bank."')";
sc_exec_sql($insert_sql);

Hi Albert, thanks by your response.
I think that the problem is get xml content on php variable.
On your example the xml content is obtained from http address.
How I can get xml client file from browse? (from scriptcase javascript control)…

Thanks

Mario Wojcik

To obtain the xml from a field in the database then you could use a database field and $xmlstring={myfield}. Same goes for a manual field. If it needs to come from a file you need to upload, then you must direct where the file is going to so you know where to get it. Next sample is using regular fopen and reads a csv:

$file = fopen({Bestandsnaam},"r");

while(! feof($file)) {
  $data = fgetcsv($file,0,chr(9));
  $data=array_pad($data, 12, 0);
  etc. 

{Bestandsnaam} contains the full (unix) path to the file.

Thanks Albert.
Ok, I need send the file to server, then get the contet.
To process will be automatic I’ll use a database field text (don?t know php very much…).
Regards
Mario Wojcik

You can upload to the database and process from there by reading the field, other option is to upload the file to a directory and process from there. But before you do you must do the 2 step approach: first the file is uploaded, next you need to commit the changes. That sounds odd, but php uses a two-step upload approach: first the file goes into a temp dir, next it will be moved to the final dir. Nothing can be done against that. So you need to use the unafterinsert event to automatically process the uploaded record. I useueally use a custom button to do that.

Hi Albert.
Sorry for my english, im spanish.

I get a code in php in a file and it works (executing the file in a local server).

$url = “https://xxxxxxxx.xml”;
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);

$data = curl_exec ($ch);
curl_close($ch);

$xml = simplexml_load_string($data);

foreach($xml->INDIVIDUALS as $ind) {
foreach($ind->INDIVIDUAL as $row){
$data_id = $row->DATAID;
$version_num = $row->VERSIONNUM;
$first_name = $row->FIRST_NAME;
$second_name = $row->SECOND_NAME;

    $sql = "INSERT INTO sujetos(data_id, version_num, first_name, last_name) 
        VALUES('$data_id', '$version_num', '$first_name', '$second_name')";
    sc_exec_sql($sql);
}

}

I want this code works in a blank in scriptcase v7. It show me the next error:
[TABLE=“class: scErrorTable, align: center, cellpadding: 0, cellspacing: 0”]
[TR]
[TD=“class: scErrorTitle, align: left”]Error[/TD]
[/TR]
[TR]
[TD=“class: scErrorMessage, align: center”]Trying to get property of non-object[/TD]
[/TR]
[/TABLE]
[TABLE=“class: scErrorTable, align: center, cellpadding: 0, cellspacing: 0”]
[TR]
[TD=“class: scErrorTitle, align: left”]Error[/TD]
[/TR]
[TR]
[TD=“class: scErrorMessage, align: center”]Invalid argument supplied for foreach()[/TD]
[/TR]
[/TABLE]

Thanks a lot.