Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2019-12-05 19:37:20

Patricki
New Member
Registered: 2019-12-05
Posts: 1

Import XML content to textpattern

I wonder if I can take my blogger posts, which are in xml format, and export them to textpattern.

Offline

#2 2019-12-05 20:12:03

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,269
Website GitHub

Re: Import XML content to textpattern

Short answer: yes.

Long answer: we used to have an importer baked in, but it slowly rotted so we removed it. We do have the ability in Textpattern’s core to take XML content — mostly, with a few omissions like images and files — and inject it into the database. We just haven’t exposed that functionality to the user interface to date.

To the best of my knowledge, no plugin has yet sprouted that can take advantage of the core routines to do this, but it should be fairly easy to write. It really is as simple as tossing a multi-file chooser on an admin panel so you can browse for .xml files and then squirting each one through our Importer, a bit like this:

$import = new \Textpattern\Import\TxpXML();

// Upload files to tmpdir here.
// ...

// Loop over the uploaded files and import them.
foreach (get_files_content('/path/to/tmpdir', 'xml') as $key => $data) {
    $import->importXml($data);
}

Job done. There are a few caveats like importing structure and peripheral info first, before content. This is to ensure that Sections and Categories, for example, exist before populating content, but basically that’s it.

That assumes you can massage the Blogger output into a format that Textpattern accepts. If not, you’d have to find a way to transform it (or code the import plugin to allow mapping, perhaps via XSLT which I know very little about).

For the required file formats, take a look in the ‘textpattern/setup’ directory. There are two directories in there which you can browse to find .xml files to learn the required structure for import:

  1. ‘articles’ contains the welcome article text.
  2. ‘data’ contains content for other tables, like categories and links and sections, etc.

If you need any further info on any of this, or a plugin throwing together to help, just shout here and someone will likely step up.

Last edited by Bloke (2019-12-05 20:25:02)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB