Question

I am trying to import each story into an object. Each object will have multiple strings (start and end) along with arrays generated from content in the additional-content. An small example would be:

<feed>
  <story>
    <run>
      <start>1/1/2012</start>
      <end>3/1/2012</end>
    </run>
    <additional-content>
      <content>
         <sample>Sample story example</sample>
      </content>
      <content>
         <sample>Sample story example</sample>
      </content>
    </additional-content>
</story>
...
</feed>

I all the xml being imported to a string. Also, I am trying to do this without libraries. I understand looping through each story but am unsure how to load the content into the object while also generating the array correctly. Any help would be appreciated.

Was it helpful?

Solution

simplexml loads xml into an object and you'll be able to work with it exactly as you're asking.

$xml = simplexml_load_string($stories);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top