Well, I've working on XML with Cake recently, and I choose to convert
the XML to array and then work on the arrays, before converting the
array back to an XML

It works well for me !

On Feb 6, 9:56 pm, misterjinx <mariusbarbulesc...@gmail.com> wrote:
> Hello,
>
> I'm trying to figure out how to modify the content of an xml document
> using the xml core library, but i don't succeed at appending the newly
> created element at the root element. First of all, I have the
> following structure of my xml file:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <playlists>
>     <playlist id="1">
>         <song>
>             <title>A new song</title>
>             <filename>A_new_song.mp3</filename>
>         </song>
>         <song>
>             <title>A second song</title>
>             <filename>A_second_song.mp3</filename>
>         </song>
>     </playlist>
>     <playlist id="2">
>         <song>
>             <title>A new song</title>
>             <filename>A_new_song.mp3</filename>
>         </song>
>     </playlist>
> </playlists>
>
> And here's how i'm trying to append a new 'playlist' element to the
> root element:
>
>         $xml = new Xml( 'playlists.xml' );
>
>         $new_playlist = $xml->createElement( 'playlist' );
>         $new_playlist->addAttribute( 'id', 123456 );
>
>         $song = $xml->createElement( 'song' );
>         $title = $xml->createElement( 'title' );
>         $title->append( $xml->createTextNode('New song title'));
>         $song->append($title);
>
>         $filename = $xml->createElement( 'filename' );
>         $filename->append( $xml->createTextNode('New song
> filename') );
>         $song->append($filename);
>
>         $new_playlist->append( $song );
>
>         $xml->append($new_playlist);
>
> Doing like this, the newly created element isn't added to the root
> element (playlists), it is added after it. And I can't find a method
> in the Xml library that would allow me to append (or in some cases
> modify some element) this newly created element to the root element.
>
> Does anyone of you know how can i obtain the result i want? Thanks.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to