How do I use entity_metadata_wrapper to create a node and at the same time multiple node references? I have an XML response from a REST api call that returns an object with an array of sub-objects contained in it.

I need to create a node with all the properties of the top level object and node references to nodes created from the sub-objects. I probably will make them nodes but I would prefer to use the Entity API instead of the Node API even if they are nodes.

&lt;toplevel&gt;
  &lt;prop1&gt;&lt;/prop1&gt;
  &lt;prop2&gt;&lt;/prop2&gt;
  &lt;array_of_sub_objects&gt;
    &lt;sub1&gt;
      &lt;sub_prop1&gt;&lt;/sub_prop1&gt;
      &lt;sub_prop2&gt;&lt;/sub_prop2&gt;
      &lt;sub_prop3&gt;&lt;/sub_prop3&gt;
    &lt;/sub1&gt;
    &lt;sub2&gt;
      &lt;sub_prop1&gt;&lt;/sub_prop1&gt;
      &lt;sub_prop2&gt;&lt;/sub_prop2&gt;
      &lt;sub_prop3&gt;&lt;/sub_prop3&gt;
    &lt;/sub2&gt;
  &lt;array_of_sub_objects&gt;
&lt;/toplevel&gt;


Here is an example of 3 objects with 2 contained inside the 1. I need to create 3 nodes or entities with an entity reference of the 2 sub-objects to the toplevel object. How do I use the Entity API to programmatically do this?
You should probably look at Migrate module. IT has support to import xml data into nodes.