1

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.

<toplevel>
  <prop1></prop1>
  <prop2></prop2>
  <array_of_sub_objects>
    <sub1>
      <sub_prop1></sub_prop1>
      <sub_prop2></sub_prop2>
      <sub_prop3></sub_prop3>
    </sub1>
    <sub2>
      <sub_prop1></sub_prop1>
      <sub_prop2></sub_prop2>
      <sub_prop3></sub_prop3>
    </sub2>
  <array_of_sub_objects>
</toplevel>

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?

1

You should probably look at Migrate module. IT has support to import xml data into nodes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.