? importexportapi.simpleXML.patch
Index: engines/importexportapi_xml.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/importexportapi/engines/importexportapi_xml.inc,v
retrieving revision 1.11
diff -u -p -r1.11 importexportapi_xml.inc
--- engines/importexportapi_xml.inc	7 Feb 2007 13:09:25 -0000	1.11
+++ engines/importexportapi_xml.inc	25 Apr 2009 00:09:58 -0000
@@ -93,16 +93,3 @@ function importexportapi_xml_build_alt_k
     importexportapi_set_def($field_array, $values);
   }
 }
-
-/**
- * Loads the MiniXML 3rd party XML library.
- *
- * @return
- *   A new MiniXMLDoc object.
- */
-function _importexportapi_include_minixml() {
-  $path = './'. drupal_get_path('module', 'importexportapi') .'/libraries/minixml/minixml.inc.php';
-  require_once($path);
-
-  return new MiniXMLDoc();
-}
Index: engines/importexportapi_xml_get.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/importexportapi/engines/importexportapi_xml_get.inc,v
retrieving revision 1.14
diff -u -p -r1.14 importexportapi_xml_get.inc
--- engines/importexportapi_xml_get.inc	7 Feb 2007 13:09:25 -0000	1.14
+++ engines/importexportapi_xml_get.inc	25 Apr 2009 00:09:58 -0000
@@ -16,13 +16,10 @@ function importexportapi_xml_get($def, $
     return NULL;
   }
 
-  // Let MiniXML do the hard work.
-  $xml_doc = _importexportapi_include_minixml();
-  $xml_doc->fromString($variables['raw']);
-
-  $import = $xml_doc->toArray();
-  unset($xml_doc);
-  $import = $import['drupal'];
+  // Let SimpleXML do the hard work.
+  $import = array();
+  SimpleXML_toArray(new SimpleXMLElement($variables['raw']), $import);
+  
   $data = array();
   $get = $def['#get'];
 
@@ -167,3 +164,53 @@ function _importexportapi_xml_get(&$fiel
     }
   }
 }
+
+/**
+ * Convert a SimpleXMLElement to an array.
+ */
+function SimpleXML_toArray($obj, &$arr) {
+  $children = $obj->children();
+  
+  // If all the children are the same key, we throw in a child tag with that
+  // key and add all the children on, numerically. We also use that as the new
+  // 'current' tag.
+  if ($key = _SimpleXML_childKey($children)) {
+    $arr[$key] = array();
+    $cur = &$arr[$key];
+    $like = TRUE;
+  }
+  // Otherwise, we just use the same tag as 'current'.
+  else {
+    $cur = &$arr;
+    $like = FALSE;
+  }
+  
+  foreach ($children as $name => $node) {
+    // If we didn't find a key above, we use this child's name, otherwise
+    // we do it numerically.
+    $idx = empty($key) ? $name : count($cur);
+    $cur[$idx] = trim((string) $node);
+    
+    // No value? There's more children.
+    if (empty($cur[$idx])) {
+      $cur[$idx] = array();
+      SimpleXML_toArray($node, $cur[$idx]);
+    }
+  }
+}  
+
+/**
+ * A little logic to find if an array of children share the same key. If so, it's returned.
+ */
+function _SimpleXML_childKey($children) {
+  $key = NULL;
+  foreach ($children as $k => $child) {
+    if (!isset($key)) {
+      $key = $k;
+    }
+    if ($key != $k) {
+      return NULL;
+    }
+  }
+  return $key;
+}
Index: engines/importexportapi_xml_put.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/importexportapi/engines/importexportapi_xml_put.inc,v
retrieving revision 1.13
diff -u -p -r1.13 importexportapi_xml_put.inc
--- engines/importexportapi_xml_put.inc	7 Feb 2007 13:09:25 -0000	1.13
+++ engines/importexportapi_xml_put.inc	25 Apr 2009 00:09:58 -0000
@@ -42,16 +42,11 @@ function importexportapi_xml_put($data, 
     $entity_count[$entity['#id']]++;
   }
 
-  $export = array('drupal' => $export);
-
-  // Let MiniXML do the hard work.
-  $xml_doc = _importexportapi_include_minixml();
-  $xml_doc->fromArray($export);
-
-  $return = $xml_doc->toString();
-  unset($xml_doc);
-
-  return $return;
+  // Let SimpleXML do the hard work.
+  $xml = SimpleXml_fromArray($export, 'drupal');
+  $xml = SimpleXML_format($xml);
+  
+  return $xml;
 }
 
 /**
@@ -172,3 +167,49 @@ function _importexportapi_xml_put_check_
 
   return $specialchars;
 }
+
+/**
+ * Got some of this code from 
+ * http://snipplr.com/view/3491/convert-php-array-to-xml-or-simple-xml-object-if-you-wish
+ */
+function SimpleXml_fromArray($data, $root) {
+  $xml = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><$root />");
+  return _SimpleXml_fromArray($data, $xml, $root);
+}
+
+function _SimpleXml_fromArray($data, $xml, $root) {
+  // Loop through the data passed in.
+  foreach ($data as $key => $value) {
+    // If there is another array found recrusively call this function
+    if (is_array($value)) {
+      // Numeric arrays will use the parent tag.
+      if (isset($value[0])) {
+        $node = $xml;
+      }
+      else {
+        if (is_numeric($key)) {
+          $key = $root;
+        }
+        $node = $xml->addChild((string) $key);
+      }
+      // Recursive call.
+      _SimpleXml_fromArray($value, $node, $key);
+    }
+    else {
+      // Add single node.
+      $value = htmlentities($value);
+      $xml->addChild($key, $value);
+    }
+  }
+  // Pass back as string. or simple xml object if you want!
+  return $xml->asXML();
+}
+
+function SimpleXML_format($xml) {
+  $pretty = new DOMDocument('1.0');
+  $pretty->preserveWhiteSpace = FALSE;
+  $pretty->loadXML($xml);
+  $pretty->formatOutput = TRUE;
+
+  return $pretty->saveXML();
+}
