Please wait...

Creating Tables in WordPress based on 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: 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.

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:

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.

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.

Please open your WordPress admin, and:

Create a table linked to an existing data source

1. Go to wpDataTables -> Create a Table and choose 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 which will help you to find it later.
3. Choose 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 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 Apply 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. Disable Table titleRows per page, Info block and enable Hide until loaded, Limit table width on “Display” tab.
2. Disable Main search block on “Sorting and filtering” tab.
3. Disable all options in Buttons selectbox on “Table tools” tab.
4. Set Displayed header for “HP” column as “Horse Power“, for “Year” column as “Year of Manufacture“.
5. Set Filter type for “Make” and “Displacement” columns as “Select box“, for “Horse Power” and “Year of Manufacture” columns as “Number Range“.

When you’ve done with configuration, click “Save” once again so wpDataTables would 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 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.