XML Imports

The code of Server Connect is very easy to extend, you could create your own formatters or modules. Problem is that the custom code is not recognized by Wappler, so you are not able to use them from the UI in Wappler, you have to add it all manually.

There were already some posts here in the forum with custom formatters for PHP.

Here a sample of how a module would become:

<?php

namespace modules;

use \lib\core\Module;
use \lib\core\Path;

// class should extend Module
class xml extends Module
{
  // all public function will be available as actions
  // parameters are always $options and $name
  // $options will contain the options for the action
  // $name is the name of the action
  public function import($options, $name) {
    // parseObject will parse all expressions it finds in options
    $options = $this->app->parseObject($options);

    // for the example I keep it simple, a better xml to json can be found at
    // https://outlandish.com/blog/tutorial/xml-to-json/
    // Path::toSystemPath is a helper method to convert the path selected in Wappler to a system path
    return simplexml_load_file(Path::toSystemPath($options->path), 'SimpleXMLElement', LIBXML_NOWARNING);
  }
}

save the file as xml.php in the dmxConnectLib/modules folder.

Your action file from Wappler contains a json that describes the actions it should run.

calling the above custom module step will look like:

{
  "name": "myImport",
  "module": "xml",
  "action": "import",
  "output": true,
  "options": {
    "path": "/data.xml"
  }
},

name : property name for the output, will also be given to the action method as parameter
module : name of the module (filename and classname should be names so)
action : name of the method to call from the module
output : should the result be added to the output json
options : options passed to the action method

Please be aware that you have to edit it by hand, there is no support for it within Wappler. Also I can’t promise that Wappler would not overwrite your code, so better have a backup of it. And you will need enough PHP knowledge to code your own modules.

3 Likes

Thanks for the information @patrick - I will give this a try. PHP is no problem at all - I would LOVE to see a proper interface where we could add exactly this information into a flow rather than having to hack the json and potentially lose it if we edit it again. Is this something that could be supported do you think? I think this would really open up some use cases.

I also encountered an external API service that passes data in XML format. Support cdjackson.
We should not forget that the CommerceML data exchange format is still the main one in many ERP systems.

Hi Patrick, i have a problem importing a very small xml,

No errors but nothing imported…Help will be very appreciated…

image
This is the xml. Is it ok?
I want to specify that importing csv is not a problem, i did it many times before. Importing xml is a problem for me.

The Import XML expects a specific structure, you can’t load just any XML with it.

What’s wrong with this xml?

There is nothing wrong with the XML, but the standard XML Import that is available in Wappler does only understand the XML structure as generated by the Export step.

To have custom xml import you have to use a custom action: XML Imports

1 Like

Done; Thks.