XML output - possible with Wappler?

I have a number of PHP files which create XML output in a number of formats required by a company which harvests this data for various purposes.

At the beginning of a files I add:
<?php header("Content-type: text/xml"); ?>
…and then create database connections etc…

The main part of the script in one example creates the XML data like this:

When the file is executed, the result is something like this:

image

Obviously this all needs to be done server-side. Is there any way of creating such output with Wappler?

You can use the Export XML file server action:

image

Thanks George,

As far as I can see, the export option would need to more flexible in order to create the format I need. I need the date_update element to appear once, then a list of IDs. Also, the data is wrapped in CDATA tags. It would be useful to be able to switch this off.

Other formats I need to create are more complicated - it’s probably not reasonable to expect an export facility to offer such flexibility. Perhaps sticking to PHP is the only solution.

Yes current implementation is just a data export and allows only root element en repeating element customization. CData is always used to avoid encoding problems.

I think there are a few things which would make the export options more useful - eg being able to choose/change the column names. But I don’t imagine it would be feasible to allow for all the possibilities.

What might be more useful would be to have options in server connect to create/manipulate files (like PHP’s fopen etc.). Eg to create an XML sitemap in the format below, I create a variable containing the reults of two queries: one on a table of static filenames, the second on the products table - and then write the query to a file. Given Wappler’s emphasis is on the visual and the client-side, this type of functionality is probably not on the horizon - and perhaps it will always be necessary to code in PHP to some extent (but it would be nice to have such features in Wappler).

<urlset>
<url>
<loc>http://www.mysite.com/somepage.php</loc>
<lastmod>2019-01-10</lastmod>
<changefreq>monthly</changefreq>
<priority>0.5</priority>
</url>

Well as for the column names they just depend on your initial data source like if it is query just select the fields you want and give them the names you want as aliases

This would work in the case of the static tables; there are indeed columns corresponding to the XML elements. In the case of the dynamic data from the product table, these columns don’t exist. The values are set as defaults within the PHP script, but could be determined by rules etc… I don’t think any export facility would cope with what might be needed to create such files - new file creation options would be needed.

On a related matter, I’ve just found out that aliases can be set by using variables, although there is nothing to suggest this (lightning bolt icon):

image

This is useful. Perhaps the little icons should be added, unless the option isn’t fully supported (but it seems to work from a quick test).

I meant to mention that it would be useful to have an option to switch this off as it won't be relevant in many cases.

1 Like

Maybe you can achieve custom output - but creating your own structure after the query.

  • Just set the query output to off
  • add custom repeater that repeats the query
  • inside add set Values - to add needed the subfields.

This should create your custom structure that you can then feed to the xml exporter for example.
You can even go recursive - but I’m not sure if the XML exporter can handle that yet :slight_smile:

Thanks. I’m sure there are options I haven’t experimented with, but I’ve updated the scripts now (they were using the old mysql extensions which have now been removed from PHP). I think it might have been a struggle to get some of these to work in Wappler, even if it were possible.

Eg I wanted to give a value to <image_url> in the XML, only if that file existed. I put the files in an array ($filelist = glob("jpegs/*.jpg") and then used in_array to check. I don’t know if this sort of thing is possible in Wappler… perhaps it is. I know I could put the files in database table (which I know is straightforward with Wappler), but don’t know if there is a direct way.

1 Like