1

I know how to add child nodes with SimpleXml and PHP but i have a problem with the orders of those child elements. Lets say i have this xml structure

album gallery1 gallery2 gallery2 . . . galleryN /album

This is how it is right now when I add childs with the basic code

$galleryElement = $sxe->addChild("gallery"); 

I want the order of child elements in this case to be on the opposite the last gallery that i will add to be first child of Album.

example:

album gallery3 gallery2 gallery1

/album

Any one knows some trick here

AXheladini
  • 1,776
  • 6
  • 21
  • 42
  • are you looking for reorder function or a "remove all and reAdd them in the correct order" is enought? – yoda Nov 17 '10 at 22:17
  • i dont want to remove and reAdd, i just need some function that when i will add new gallery this gallery will be the first child (on top of other galleryis) – AXheladini Nov 17 '10 at 22:19
  • Looks like you want to prepend rather than append? If so, check this out: http://stackoverflow.com/questions/2092012/simplexml-how-to-prepend-a-child-in-a-node – Paul Kehrer Nov 17 '10 at 22:20
  • @Paul Kehre - Thats what i am looking for, but i can not configue because i use another class for adding CData child. Can you help me to configure out how to use public function prependChild($name, $value) inside my class ? – AXheladini Nov 17 '10 at 22:33
  • @Paul Kehre - OK i configure it, is there a chance your answer to be chosen as winner ? – AXheladini Nov 17 '10 at 22:45
  • I'll add an answer if you want to choose it. Glad you got it working! – Paul Kehrer Nov 17 '10 at 23:05

1 Answers1

1

It looks like you want to prepend to your container. Unfortunately simplexml doesn't have this function natively, but this previous answer will assist you in getting it working

SimpleXML how to prepend a child in a node?

Community
  • 1
  • 1
Paul Kehrer
  • 13,466
  • 4
  • 40
  • 57