Php xml,用xml对象替换正在使用的节点

I'm facing an Xml problem. Probably something stupid but I can't see it...

Here is my Xml at start :

<combinations nodeType="combination" api="combinations">
    <combination xlink:href="http://localhost:8888/vmv/ps/api/combinations/1">
        <id><![CDATA[1]]></id>
    </combination>
    <combination xlink:href="http://localhost:8888/vmv/ps/api/combinations/2">
        <id><![CDATA[2]]></id>
    </combination>
</combinations>

So for each node, I make the API call then I want to replace the node by the returned value, like that :

$c_index = 0;
foreach($combinations->combination as $c){
    $new = apiCall($c->id); //load the new content
    $combinations->combination[$c_index] = $new;
    $c_index++;
}

If I dump the $new into the foreach, I got an simplexmlobject which is fine but if I dump the $combinations->combination[$x], I've got big string of blank...

I'd like to get :

<combinations nodeType="combination" api="combinations">
    <combination xlink:href="http://localhost:8888/vmv/ps/api/combinations/1">
        <my new tree>
            ....
        </my new tree>
    </combination>
    <combination xlink:href="http://localhost:8888/vmv/ps/api/combinations/2">
        <my new tree>
            ....
        </my new tree>
    </combination>
</combinations>

I must be missing something but what...? That's the question...

thanks for your help !

查看全部
dtpk04526211
dtpk04526211
2015/04/07 17:19
  • xml
  • php
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复