Announcement

Collapse
No announcement yet.

Send a client xml file to server

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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!

  • #2
    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.

    Code:
    $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);
    Albert Drent
    aducom software netherlands
    scriptcase partner, reseller, support and (turn-key) development
    www.scriptcase.eu / www.scriptcase.nl

    Comment


    • #3
      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

      Comment


      • #4
        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:

        Code:
        $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.
        Albert Drent
        aducom software netherlands
        scriptcase partner, reseller, support and (turn-key) development
        www.scriptcase.eu / www.scriptcase.nl

        Comment


        • #5
          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

          Comment


          • #6
            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.
            Albert Drent
            aducom software netherlands
            scriptcase partner, reseller, support and (turn-key) development
            www.scriptcase.eu / www.scriptcase.nl

            Comment

            Working...
            X