I have the below code which creates an object and then converts the object into XML. As you can see I have this in a loop as I have multiple objects. I do not want to create a new XML file for each object, I want them all in the same XML file. I therefore somehow need to combine the objects prior to adding them to the XML within this loop. Anyone any ideas how?
$orderObj1 = new Order();
$orders = $orderObj1->getAllOrders();
foreach ($orders as $order => $orderdetail){
//create Order XML from object
$orderObj2 = new Order($orderdetail['id']);
}
$serializer = new XML_Serializer();
// set name for root element
$serializer->setOption("rootName", "orders");
//add the XML declaration
$serializer->setOption("addDecl", "true");
$result = $serializer->serialize($orderObj2);
if($result === true) {
$orders_xml = $serializer->getSerializedData();
}
echo $orders_xml;