Voting

: six minus two?
(Example: nine)

The Note You're Voting On

thomas at guenneguez dot com
13 years ago
Merge two xml only with SimpleXML :
Function corrected if note containe only value.

<?php
function mergeXML(&$base, $add)
{
if (
$add->count() != 0 )
$new = $base->addChild($add->getName());
else
$new = $base->addChild($add->getName(), $add);
foreach (
$add->attributes() as $a => $b)
{
$new->addAttribute($a, $b);
}
if (
$add->count() != 0 )
{
foreach (
$add->children() as $child)
{
mergeXML($new, $child);
}
}
}
?>

Use : <?php mergeXML($xmlElement, simplexml_load_string($toMerge)) ?>

<< Back to user notes page

To Top