Please wait...

How to create tables in WordPress with XML input

Video versionA video overview of XML-based wpDataTables

Example of a XML-based wpDataTablewpDataTable created from XML input

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

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

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

Let’s view the resulting table first. The step-by-step tutorial on how to generate it follows:

If your data set is quite large (many thousands of rows) the 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.

Prepare the data source in correct XML format

You first need to prepare the data source in the correct XML format. Please check these 3 conditions:

1. The data set should not be empty, but 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 is able to access.

In this example, we will use a sample XML data set available from this link. You can copy 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.

Open your WordPress admin, and:

Create a table linked to an existing data source

1. Go to wpDataTables -> Create a Table and choose the Create a table linked to an existing data source option.

Creating Tables in WordPress from XML

2. Define a name for your new wpDataTable in the Table title input. This will help you to find it later.
3. Choose the XML option in the Input data source type selectbox.
4. Paste the URL of your XML data set to the Input file path or URL input field.
5. Press Apply, so wpDataTables can 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 Apply, wpDataTable has now been 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 for some of its columns. For the table above we defined these additional settings:

1. Disable Table titleRows per page, Info block and enable Hide until loaded, Limit table width on the “Display” tab.
2. Disable the Main search block on the “Sorting and filtering” tab.
3. Disable all options in the Buttons selectbox on the “Table tools” tab.
4. Set the Displayed header for “HP” column as “Horse Power“, and the “Year” column as “Year of Manufacture“.
5. Set the Filter type for “Make” and “Displacement” columns as “Select box“, for “Horse Power“, and the “Year of Manufacture” columns as “Number Range“.

When you’ve done with your configuration, click “Save” once again so wpDataTables can store them.

Insert your XML-based table to WordPress post or page

Inserting wpDataTables shortcode on page or post

Now the table is prepared, and the only thing remaining is to insert it in our post or page.

1. Open or create a new post or page.
2. Put the cursor in the position where you want 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 3000+ 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.

By clicking "subscribe" you consent that the information you provide via this form will be securely processed and stored in compliance with EU privacy laws (GDPR).
This  information will be used to send you newsletters as well as pre-populate any forms, should you want to edit your newsletter preferences.
You can always use this link to unsubscribe from the newsletter. You can see our Privacy Policy here.