I have an XML file and a CCK content type defined. I want to import the XML into nodes (there's about 200 nodes worth). I need to do a simple mapping between the fields I've defined and the XML schema. then let it rip.

But it appears that nothing exists to do this.

I've looked in forum threads and different docs. I was excited about the Transformations module (http://drupal.org/project/transformations), but it appears a little limited. However, the Migrate module seems to hold a lot of promise (http://drupal.org/project/migrate). Alas, I can't find anything that yields details on how to get this done. The Migrate docs are...well, it's documented that they need to be documented :-)

So, has anybody used Migrate (or other tool) to import XML into CCK content nodes? (Maybe Moshe will reply :-)

Comments

garpy’s picture

lkd’s picture

Looks like it's just for CSV and TSV, not XML. Did I miss something?

sphopkins’s picture

I am in the same place as you - I have thousands of XML files to import into CCK content fields, and my only solution so far has been to have a consultant convert the multiple XML to a single CSV and then use node_import to import the content.

I hope there comes to be a better solution but for now that is what I have done.

lkd’s picture

I'm not sure if you need a consultant. I hand-wrote some XSLT to convert the XML into a CSV and TSV file (I did both just to see which one would work best with node_import). It wasn't very hard if you have some basic programming skills. I used Saxon (http://www.saxonica.com/) for the transformation tool. Worked great!

Here's a simplified version of what you would do for TSV (replace 	 with a "," for CSV)

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="text"/>
<xsl:template match="A_COLLECTION_OF_XML_THINGS_IM_INTERESTED_IN">
<xsl:text>Field type 1	Field type 2	Field type 3&#xa;</xsl:text>
<xsl:for-each select="AN_INDIVIDUAL_ITEM">
<xsl:value-of select="FIELD_1"/><xsl:text/><xsl:text>&#x9;</xsl:text>
<xsl:value-of select="FIELD_2"/><xsl:text/><xsl:text>&#x9;</xsl:text>
<xsl:value-of select="FIELD_3"/><xsl:text/>&#xa;</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

Play around with this and see how things go!

sphopkins’s picture

I will look at that, but the fun was that I had the consultant anyways ;-)