code: public function addMissing($objStructure, &$objElement)
      {
          // Set missing attributes
          foreach ($objStructure->attributes() as $strName => $objAttribute) {
              if (!isset($objElement->attributes()->$strName)) {
                  $objElement->addAttribute($strName, (string)$objAttribute);
              }
          }
  
          // Add missing nodes
          foreach ($objStructure->children() as $strName => $varNode) {
              if (count($varNode) > 0) {
                  // Due to a PHP bug clone does not work
                  $objNode = $objElement->addChild($strName);
                  $this->addMissing($varNode, $objNode);
              } else {
                  $objElement->addChild($strName, (string)$varNode);
              }
          }
      }
docs: Add missing nodes and attributes to an element from a strucure element
  Had to be written like this because clone does not work on SimpleXmlElements
  
  @param $objStructure
  @param $objElement