Last updated 12 March 2012. Created on 12 March 2012.
Edited by adamfranco. Log in to edit this page.

Documentation for the NodePorter module.

About NodePorter

The NodePorter Exporter and NodePorter Importer modules work hand-in-hand to export nodes to an XML description or import nodes from an XML description.

These modules can be used to programatically import content from other systems and data sources or export content and import it into other Drupal sites.

NodePorter uses the FieldTool module in Drupal 6 to export CCK types.


In Drupal 6 you must have the FieldTool module installed to export CCK fields.

NodePorter has three separate modules that can be enabled independently as needed: NodePorter Exporter, NodePorter Importer, and NodePorter Importer UI.


Exporting Nodes to XML

After enabling the NodePorter Exporter module, point your browser at DRUPAL_BASE/nodeporter/export/NID where NID is any node id in your system. This will generate an XML document with the following structure:

<?xml  version="1.0" ?>
<nodes xmlns=''>
	<node type="course_metadata" nid="1863" vid="1863" language=""
	user_mail="" status="1" created="1297263879"
	changed="1300235166" comment="0" promote="0" moderate="0" sticky="0"
	tnid="0" translate="0" format="2">
		<title><![CDATA[Test Page]]></title>
		<body><![CDATA[<p>Lorem ipsum dolor sit amet, consectetur adipiscing
elit. Maecenas id risus dui, eu egestas tellus. Vestibulum interdum
tellus ut velit mattis lacinia. Proin vitae mi vitae urna dignissim
porta! Donec libero ligula, accumsan sit amet dapibus pulvinar,
dignissim nec odio. Cras fermentum, turpis eu vulputate suscipit, orci
lacus pulvinar enim, at tempor sem tellus in arcu. In bibendum risus
volutpat arcu varius hendrerit. Morbi imperdiet aliquam nulla ac

<p>Donec felis nibh, adipiscing vitae aliquam vitae, sollicitudin quis dui.
Donec mattis scelerisque nisl vitae dictum? Fusce posuere condimentum ligula;
sit amet congue diam suscipit sit amet. Nulla consequat massa id ligula
aliquam elementum. Suspendisse potenti. Curabitur at dictum lorem. Nullam eu
tristique neque. Ut viverra velit id ante elementum nec fermentum leo egestas.
Nulla pellentesque adipiscing justo ut blandit. Nullam in metus vitae odio
posuere sollicitudin nec non nulla. Donec a nulla tincidunt felis sodales
varius. Maecenas eleifend, justo eu ultricies ullamcorper, lacus sem blandit
lectus, eu interdum tellus eros sed lacus? Phasellus mi sem, convallis ac
posuere sit amet, pellentesque sit amet nisl. Praesent eu magna turpis, sit
amet ornare urna. Cras adipiscing dui non lacus lacinia vel molestie velit
euismod. Duis adipiscing, sapien id gravida rutrum, lorem metus mattis velit;
eu imperdiet urna felis sed mauris. </p>]]></body>
		<teaser><![CDATA[<p>Lorem ipsum dolor sit amet, consectetur adipiscing
elit. Maecenas id risus dui, eu egestas tellus. Vestibulum interdum
tellus ut velit mattis lacinia.</p>]]></teaser>
		<field_offering_id cck_field_type='text'>
		<field_short_name cck_field_type='text'>
			<value><![CDATA[TEST 0101A]]></value>
		<field_term_id cck_field_type='text'>
		<field_term_label cck_field_type='text'>
			<value><![CDATA[Spring 2011]]></value>
		<field_term_start_date cck_field_type='text'>
		<field_term_end_date cck_field_type='text'>
		<field_term_weeks cck_field_type='number_integer'>
		<field_catalog_id cck_field_type='text'>

If you wish to export all nodes in the system, you can point your browser at DRUPAL_BASE/nodeporter/export_all.

Importing Nodes from XML via the user-interface

After enabling the NodePorter Importer and NodePorter Importer UI modules you will find an Import Nodes menu option under Administer » Content Management. Paste the XML you previously exported (or XML of a similar structure) into the form and submit.

The key attribute in the XML is the <node nid=""... attribute. if the nid attribute exists and matches an existing node, then the existing node will be updated with the contents from XML. If the nid attribute is empty, then a new node will be created with the contents from XML.

Importing Nodes from XML programatically

The NodePorter module is most useful when used programatically to bulk create/update content. Your custom scripts can simply call nodeporter_importer_import_string($xmlString) to import nodes from XML. This function will return an array of the node ids that were imported so that further reporting or updates can be applied.

Extending NodePorter

The NodePorter modules can be extended via several hooks to allow other modules to import or export additional information.

In addition to implementing hooks to change how nodes are imported or exported, other modules can use the NodePorter functions directly, wrapping importing of nodes in larger processes. The MMPorter modules do this to allow exporting and importing of Monster Menus page hierarchies and permissions. Nodes are placed on Monster Menus pages and permissions are added to the node elements via the hooks below.

Export Hooks

Node Attributes

 * Print out attributes for the node during export.
 * @param object $node
 * @return null
function hook_np_print_node_attras ($node);

Implementations of this hook should print XML attribute strings. For example:

 * Implementation of hook np_print_node_attras($node).
function mymodule_np_print_node_attras($node) {
  print ' myattra="'.$node->myproperty.'"'; 

Node Elements

 * Print out content, fields, and additional elements for the node during export.
 * @param object $node
 * @return null
function hook_np_print_node_contents ($node, $tabs = "\t");

Implementations of this hook should print XML element strings. For example:

 * Implementation of hook np_print_node_contents($node).
function mymodule_np_print_node_contents($node, $tabs = "\t") {
  print "\n".$tabs."".$node->myproperty."";

Import Hooks

 * Populate a node with data from the XML during import.
 * @param object $node
 * @param DOMElement $nodeElement
 * @param DOMXPath $xpath
 * @return The populated node.
function hook_np_populate_node ($node, DOMElement $nodeElement, DOMXPath $xpath);

Implementations of this hook should look through the DOMElement for the node for their attributes or tags an apply their contents to the $node object. For example, a taxonomy module might look for <tag>tagname</tag> elements and add them to the node.

Looking for support? Visit the forums, or join #drupal-support in IRC.