开发者

Merge xml in PHP DOM

i want to merge a PHP DOMDocument in another..

//this creates the DOM which will be imported
function element_index(..)
{
$skrit=new DOMDocument();
$skrit->loadXML('<krits:kriti xmlns:krits="http://test.de/krits">..</krits:kriti>');
return $skrit;
}

function crawl_xml($element)
{
//thats the line where to get the result and merge      
$skrit=element_index(..);
$temp3=$skrit->documentElement->cloneNode(true);
$element->appendChild($xpIn->importNode($temp3));
}

//thats how i start the recurisve walking through Nodes
$xpIn = new DOMDocument();
crawl_xml($xpIn->firstChild);

The input/output should like this:

<!--input-->
<all><one/></all>

<!--input new to add-->
<krits:kriti xmlns:krits="http://test.de/krits">..</krits:kriti>

<!--ouput-->
<all><krits:kriti xmlns:krits="http://test.de/krits">..</krits:kriti><one><krits:kriti xmlns:krits="http://test.de/krits">..</krits:kriti></one></all>

maybe importNode might be not a good choice? The cloneNode I used because I hoped to avoid problems with recursive call.. So 开发者_运维百科what i am doing wrong? Thanks for your help!


If you want to import the whole node sub-tree (and not just the node itself), you need to set $deep to true in importNode:

$domDocument->importNode($node, true);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜