grouping XML objects [closed]
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this questionLooking for a way to add a couple of Simple XML objects together. The goal is to output them as a single XML doc but as separate entries in the XML dom. I'm not sure how to accomplish this. The objects are in an array like this:
Array (
[0] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[no] => 23432423
[type] => Array
)
[id] => 40043030
[title] => Cars
[cinemadate] => 2011-07-06
[changedate] => 2011-07-27T10:19:00
[year] => 2011
[length] => 112
[genres] => SimpleXMLElement Object
(
[genre] => animatie
)
[1] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[no] => 48050593
[type] => Array
)
[id] => 1231676
[title] => Arrietty
[cinemadate] => 2011-07-06
[changedate] => 2011-06-21T10:39:00
[genres] => SimpleXMLElement Object
(
[genre] => animatie
)
I would revert to DOM
for this, there is only so much Simple XML can do:
$node = new SimpleXMLElement('<root/>');
$domnode = dom_import_simplexml($node);
foreach($arr as $simplexmlelement){
$domnode->appendChild(
$domnode->ownerDocument->importNode(dom_import_simplexml($simplexmlelement),true)
);
}
$node = simplexml_import_dom($node);
echo $node->asXML();
精彩评论