Please wait...

Creating Tables in WordPress based on XML input

Video versionA video overview of XML-based wpDataTables

Example of a XML-based wpDataTablewpDataTables Table created from XML input

XML (eXtensible Markup Language) is a many-year standard for data exchange between all kind of software platforms, online and offline. Many web services “run” on XML, and wpDataTables supports XML as an input data source as well of course.

In this tutorial we will use a dummy (randomly generated) automobiles database in XML format, that you can download via this link.

Let’s see the resulting table first, and step-by-step tutorial on how to generate it follows:

XML example - cars database

Please note: if your data set is really large (many thousands of rows) XML format for creating a wpDataTable would not be a good solution since the page generation time and size would significantly increase. MySQL-based wpDataTables with server-side processing is the best option for large datasets.

When working with XML format please note: at the moment wpDataTables accepts this and only this format of XML (see example): a single root node with a number of child nodes (one level), where each child node will be treated as row, and child row attributes as cells. If your software does not return this format you would need to prepare e.g. some PHP adapter to return one of the formats that wpDataTables would accept

Prepare the data source in correct XML format

First you would need to prepare the data source in correct XML format. Please check these 3 points:

  1. The data set should not be empty, it should contain at least 1-2 rows.
  2. The returned XML should exactly follow the format highlighted above: a single root node, with one level of same-structured child nodes; where the child nodes will be parsed as rows, and their attributes as cells.
  3. The XML should be available via an URL that wpDataTables would be able to access.

In this example we will use a sample XML data set available by this link. You can copy it and paste it to your new wpDataTable if you would like to follow the steps of this tutorial.

Create a new wpDataTable and paste the URL of your XML

Now we need to create a wpDataTable based on the XML data source that we prepared.

  1. Go to WordPress admin, and open wpDataTables -> Add from Data Source.
  2. Define a name for your new wpDataTable in the “Table title” input which will help you to find it later.
  3. Choose “XML” option in the “Table type” select box.
  4. Paste the URL of your XML data set to the “Input file or URL” input field.
  5. Press “Save” so that wpDataTables would read the table data and initialize the columns metadata from the provided XML input.

(Optional) - Define additional settings for the table and columns

After you clicked “Save” wpDataTable is already created, and available to be inserted in posts or pages, but you might want to define some additional settings for the table in general, or some of its columns. For this table above we defined these additional settings:

  1. Set “Displayed header” for “HP” column as “Horse Power“, for “Year” column as “Year of Manufacture“.
  2. Set “Filter type” for “Make” column as “Select box“, for “Displacement” column as “Select box“, for “Horse Power” column as “Number Range“, for “Year of Manufacture” column as “Select box“.

When you’ve done with configuration, click “Save” once again so wpDataTables would store them. You can also click “Preview” to see in a popup how will the table look in the front-end.

Insert your XML-based table to WordPress post or page

Now the table is prepared and the only thing we need to do is to insert it to our post or page.

  1. Open or create a new post or page.
  2. Put the cursor in the position where you would like to place the wpDataTable.
  3. Click the “Insert wpDataTable” button in the editor.
  4. Locate the wpDataTable that you created in the steps 1-3 and click OK.
  5. Save the post or page and open it in the front-end to see the result.

As an alternative, you can paste the generated wpDataTable shortcode manually.

Never miss new features!

Join 2000+ newsletter subscribers

Never miss notifications about new cool features, promotions, giveaways or freebies - subscribe to our newsletter! We send about one mail per month, and do our best to keep our announcements interesting.

We never spam or disclose your address to anyone.