|
Posted by Janwillem Borleffs on 06/18/06 14:38
Adriαn Ribao wrote:
> So, I can't do it with ImportNode and AppendChild. I have no idea how
> to do it.
> Can someone help me please?
>
The following isn't pretty, but might give you some ideas, as there doesn't
seem to be a straightforward way of doing what you want:
<?php
$xml =<<<EOX
<root>
<one />
<two>
Hello
<three>World</three>
</two>
</root>
EOX;
$xml2 =<<<EOX
<whatever>
<node />
</whatever>
EOX;
function appendChildNodes(DomDocument $targetdoc,
DOMNode $targetnode,
DOMNodeList $nodelist) {
foreach ($nodelist as $item) {
$node = $targetdoc->importNode($item, true);
$targetnode->appendChild($node);
}
}
$doc = DomDocument::loadXML($xml);
$doc2 = DomDocument::loadXML($xml2);
$source = $doc->documentElement
->getElementsByTagName('two')->item(0);
$target = $doc2->documentElement
->getElementsByTagName('node')->item(0);
appendChildNodes($doc2, $target, $source->childNodes);
print $doc2->saveXML();
?>
HTH;
JW
Navigation:
[Reply to this message]
|