How can I combine two or more simpleXML objects?
$xml1 = simplexml_load_file($file1);
$xml2 = simplexml_load_file($file2);
...
How can I combine two or more simpleXML objects?
$xml1 = simplexml_load_file($file1);
$xml2 = simplexml_load_file($file2);
...
You can typecast the XML into an array, merge ( http://php.net/manual/en/function.array-merge.php) it, then typecast back to an object. Like so:
$xml = (object)array_merge((array)$xml1, (array)$xml2);
You can create a new class and add those objects to the class to get a combined object.
class myXML {
function add($xmlobj) {
foreach ($xmlobj->children() as $key=>$obj) {
$this->$key = $obj;
}
}
}
$xob1 = simplexml_load_file($file1);
$xob2 = simplexml_load_file($file2);
$xob3 = new myXML();
$xob3->add($xob1);
$xob3->add($xob2);