Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [XML][PHP] Dodanie dziecka na początek
pspgor
post 1.07.2012, 16:16:49
Post #1





Grupa: Zarejestrowani
Postów: 81
Pomógł: 0
Dołączył: 27.02.2011

Ostrzeżenie: (0%)
-----


Witam. Mam owy plik XML :

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <photos>
  3.  
  4. <config>
  5. ...
  6. </config>
  7.  
  8. <photo>
  9. <thumbnail>s_photo_101.jpg</thumbnail>
  10. <filename>photo_101.jpg</filename>
  11. <description><![CDATA[<p class="subtitle">Photo Title 01 goes here</p><p><a href="http://www.flashmo.com/donate" target="_parent">Lorem ipsum dolor sit amet</a>, consectetur adipiscing elit. <span class="highlight">Quisque at ante sit amet</span> erat laoreet <u>fermentum</u>. Quisque nec nisl. Nam scelerisque cursus dolor. Duis nulla diam, posuere ac, varius id, ullamcorper sit amet, libero.</p><p><span class="note">This text is dynamically loaded from the external XML file. This textfield supports HTML and CSS.</span></p>]]></description>
  12. </photo>
  13.  
  14. <photo>
  15. <thumbnail>s_photo_102.jpg</thumbnail>
  16. <filename>photo_102.jpg</filename>
  17. <description><![CDATA[<p class="subtitle">Photo Title 02 goes here</p><p><a href="http://www.flashmo.com/page/1" target="_blank">Fusce quis diam sit</a> amet tortor luctus pellentesque. Donec accumsan urna non elit tristique mattis. <b>Vivamus fermentum</b> orci viverra nisl. Quisque nec nisl.</p>]]></description>
  18. </photo>
  19.  
  20. ...


Do tego mam php:

  1. //wczytujemy plik z xmlem
  2. $xml = simplexml_load_file($plikxml);
  3.  
  4. //wyszukujemy interesująca nas gałąź
  5. $xmlCopy = $xml[0];
  6.  
  7. photo = $xmlCopy->addChild("photo","");
  8. $dziecko = photo->addChild("thumbnail", "s_".$nazwa);
  9. $dziecko = photo->addChild("filename", $nazwa);
  10. $dziecko = photo->addChild("description", $desc);
  11.  
  12. //zapisujemy XML'a do nowego pliku
  13. $xml->asXML($plikxml);


Jednakże po tym dziecko zostaje dodane na koniec, a koniecznie chciałbym, aby dodane zostało na początek.

W jaki sposób to zrobić?

Pozdrawiam.
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 31.07.2025 - 10:37