PHP parse XML within XML



I have an XML file that contains XML within it. How would I go about parsing everything into an array or object?



<DATA>
<ROW>
<id>1</id>
<message_id>123456789</message_id>
<brand_name>SAMPLE</brand_name>
<request_xml>
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;Email&gt;
&lt;Service&gt;
&lt;LogMessage/&gt;
&lt;Delivery&gt;
&lt;Synchronous/&gt;
&lt;/Delivery&gt;
&lt;/Service&gt;
&lt;Model&gt;
&lt;Head&gt;
&lt;From&gt;someone@example.com &lt;/From&gt;
&lt;To&gt;someone@sample.com&lt;/To&gt;
&lt;Subject&gt;Your Question&lt;/Subject&gt;
&lt;/Head&gt;
&lt;ns2:ContactUs&gt;
&lt;ns2:Sender&gt;
&lt;ns2:FirstName&gt;John&lt;/ns2:FirstName&gt;
&lt;/ns2:Sender&gt;
&lt;/ns2:ContactUs&gt;
&lt;/Model&gt;
&lt;InlineImages/&gt;
&lt;History/&gt;
&lt;/Email&gt;
</request_xml>
<http_status>400</http_status>
<created_by>admin</created_by>
<created_on>2014-09-08 01:56:59</created_on>
</ROW>
</DATA>


My goal is to end up with somthing like that:



SimpleXMLElement Object
(
[ROW] => SimpleXMLElement Object
(
[id] => 1
[message_id] => 123456789
[brand_name] => SAMPLE
[request_xml] => SimpleXMLElement Object
(
...
[LogMessage] =>
...
[from] => someone@example.com
...
)

[http_status] => 400
[created_by] => admin
[created_on] => 2014-09-08 01:56:59
)
)


I didn't put all levels of the request_xml in my example, but you get the idea. Basically I want that request_xml to be parsed like the rest of the XML file.


How could I achieve this? Thanks in advance for any help on this!


No comments:

Post a Comment