开发者

grouping XML objects [closed]

Closed. This question needs details or clarity. It is not currently accepting answers. 开发者_StackOverflow社区

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 9 years ago.

Improve this question

Looking 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();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜