Sunday, 15 September 2013

Rearrange XML nodes with PHP -


I have a dynamic banner with images / information saved in XML file. I'm adding an option to rearrange the images to the user, though they like (Jquio Sortable) and once I get a new order (which indicates the ID attribute) I copy the infos of each node and Want to rearrange without saving it again in the new order, for example:

  & lt; Banner & gt; & Lt; Banner id = "1001" & gt; & Lt; Infos ... & gt; & Lt; / Banner & gt; & Lt; Banner id = "1003" & gt; & Lt; Infos ... & gt; & Lt; / Banner & gt; & Lt; Banner ID = "900" & gt; & Lt; Infos ... & gt; & Lt; / Banner & gt; & Lt; / Banner & gt;   

Ask the user to rearrange it at 900, 1003, 1001. I would like to be able to obtain nodes by ID # and accordingly restore them. Is there an easy way to do this?

(1) a child order every and lt; Banner & gt; - Node and (2) Sort the xml by that child.

(1): $ xml Simplexml object, in order $ order ...

  $ Stored in order = array (900,1001,1003); Foreign currency ($ xml-> $ banner as banner) {foreach ($ k = & gt; $ order as $ v) if ($ banner ['id'] == $ v) $ banner- & Gt; Add Chalk ('Order', $ T); }   

(2): Sort by order xml: View accepted responses in this post:

View live-demo @

No comments:

Post a Comment